Skip to content

Allow Parser pattern size to be parametrizable #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mbenedettini
Copy link

When parsing files with big strings allowing a big pattern size can help shave off precious milliseconds making parsing considerably faster since less loops of the parser are needed, leaving the big lift to the Javascript Regexp engine.

numberFraction: /^[\.eE]/,
numberExponent: /^[eE]/,
numberExpSign: /^[-+]/
};
const MAX_PATTERN_SIZE = 16;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this const name is now confusing (compared to DEFAULT_PATTERN_SIZE) but I couldn't find a better name

@uhop uhop self-assigned this Jun 25, 2024
@uhop
Copy link
Owner

uhop commented Jun 25, 2024

@mbenedettini do you have any benchmarks showing that the speed of parsing had improved?

I am asking because /.{1,256}/ comes with a penalty for regular expression engines. For example it is less effective
than /.?/, /.*/ or /.+/, especially when the upper number is high. TBH, I had worried that {,256} is too high and
should be reduced.

@KJ7LNW
Copy link

KJ7LNW commented Jun 2, 2025

@mbenedettini do you have any benchmarks showing that the speed of parsing had improved?

I am asking because /.{1,256}/ comes with a penalty for regular expression engines. For example it is less effective than /.?/, /.*/ or /.+/, especially when the upper number is high. TBH, I had worried that {,256} is too high and should be reduced.

@mbenedettini, if possible always use string indexes (substr, etc) for parsing large volumes of data and then implemented so it scans the input only once instead of doing multiple passes. Also, never do single-character-scanning (ie for i ... str[i]) because that is slow, it should happen in delimited chunks that are as large as possible. also keep in mind that split/join are slow and memory intensive, so avoid these too.

Then your implementation can scan in hundreds of megabytes or even gigabytes per second.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants