-
Notifications
You must be signed in to change notification settings - Fork 201
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
Use RegExp sticky flag for lexer performance boost. #380
Comments
A small POC showed 8-10% improvement in an E2E (lex + parse) JSON benchmark. getting this to productive quality requires handling some issues:
|
avoiding string allocation in hot code via btw, native |
Thanks for the feedback @leeoniya
The Chevrotain Lexer is based on Regular expressions, so there is no access to individual chars.
I'm already using substring, The optimization I'm talking about here is to completely avoid using substring. By using the RegExp new sticky flag combined with changing the regExp lastIndex property it is possible to match from any point in the string. Currently Chevrotain is chopping off string prefixes using substring.
Aye, I use the good old fashioned for loops in hot spot code. |
right, i agreed that avoiding it is the right way to go. i did a similar optimization in one of my libs recently and was also surprised by how big the boost was. |
Breaking Changes
The custom match is expected to be performed beginning from the offset argument in the text. |
re-opening as a reminder to update the safari custom pattern in the performance |
Final performance results showed almost 30% for a simpler JSON Lexer. |
This is only applicable to modern JS engines. But anyone using IE11 is doomed anyways 😄 |
Safari related performance workaround was no longer needed and was removed. |
Modifying the RegExp's lastIndex instead of chopping off parts of the input string repeatedly.
The text was updated successfully, but these errors were encountered: