Skip to content
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

Ideas for perf improvements on long strings #26

Open
tjmehta opened this issue Mar 10, 2018 · 1 comment
Open

Ideas for perf improvements on long strings #26

tjmehta opened this issue Mar 10, 2018 · 1 comment

Comments

@tjmehta
Copy link
Contributor

tjmehta commented Mar 10, 2018

Hello @sallar,

Thanks for this great library! My application can potentially be running ‘substr’ on many long strings at the same time, so perf is very important. I noticed that ‘substr’ (etc) uses ‘match’ which runs the RegExp on the entire string. This can be quite expensive for long string especially if ‘substr’s ‘length’ is much shorter than the entire string.

So far I only have one idea: to use ‘exec’ with a while loop in the case that ‘length’ is much shorter than the entire ‘string’*. Do you have any other ideas for perf improvements? I would be happy to implement them and send you PRs.

*See benchmarks: https://jsperf.com/regex-exec-vs-match-for-long-strings/1

Thanks

@sallar
Copy link
Owner

sallar commented Mar 10, 2018

Hi @tjmehta, thanks!
If you think that will improve the perf, please send a PR :) It's highly appreciated.

Thanks.

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

No branches or pull requests

2 participants