-
Notifications
You must be signed in to change notification settings - Fork 9
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
Custom grammar with 'StringLiteral' much faster when using RegExps. #20
Comments
It may be related to how regular expressions are parsed, creating a regular expression with the string You could simply add an if to your patch to optimize StringLiterals without special characters using the regex path. This should do the trick. If it works feel free to send a PR. if (decoration || preDecoration || !/^[a-zA-Z0-9_-\s]+$/.test(x.text)) { |
Thank you. I wanted a few more characters to be supported, so I was able to get this working: (borrowed
I wanted |
Are you bringing back the good old |
Ha. Yeh we are going to try: vpdb/vpx-js#141 |
In #17, we had a question about case insensitive keywords.
We noticed significant performance enhancements when using RegExps for all string literals.
So for example:
LogicalOperatorExpression ::= RelationalOperatorExpression (WS ([A][n][d] | [O][r] | [X][o][r] | [E][q][v]) WS? RelationalOperatorExpression)*
is much faster than
LogicalOperatorExpression ::= RelationalOperatorExpression (WS ('And' | 'Or' | 'Xor' | 'Eqv') WS? RelationalOperatorExpression)*
As a test, we modified
Grammars/Custom.ts
:to
The above would allow you to use
'And'
in the grammar for readability, but generate abnfseq
like/A/, /n/, /d/
.In a ~3200 line vbscript, applying this to an entire grammar, shaves off nearly 400-600ms.
We also tried,
/And/
which proved worse then/A/, /n/, /d/
. (And back to case insensitive,/And/i
has worse performance than[A][a][N][n][D][d]
)I was going to submit a PR with the above change, however, running the test cases results in two errors.
Our grammar doesn't use any advanced features, so it was working great.
I must be missing something about how StringLiterals work?
FWIW, here are some benchmarks, using regexps instead of string literals:
vs:
The text was updated successfully, but these errors were encountered: