Hi. I was wondering about esprima performance. What is the thoughts and plans for improvement?
I noticed esprima is faster then Acorn but soon as V8 warms up acorn wins on large data sets.
Some of the current esprima code can be optimized to use bitmasks to gain better perf.
Im noWindowWorking on github
--
You received this message because you are subscribed to the Google Groups "esprima" group.
To unsubscribe from this group and stop receiving emails from it, send an email to esprima+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
With the suggestions above everything will stay as before. No tests breaks etc. You only get a code size reduction. Regarding benchmark, yes somehow it will have impact on the benchmark results, but you would also need to change this module
https://github.com/jquery/esprima/blob/master/src/token.ts#L1-L12
For the token, you change it toexport const enum Token {BooleanLiteral = 1,EOF = 1 << 1,Identifier = 1 << 2,Keyword = 1 << 3,NullLiteral = 1 << 4,NumericLiteral = 1 << 5,Punctuator = 1 << 6,StringLiteral = 1 << 7,RegularExpression = 1 << 8,Template = 1 << 9,};Note the *const* before the enum. Meaning when you compile the source, you save bytes again because it will be a replaced by numbers.
And this one has to be switched into a function to make V8 happy.
https://github.com/jquery/esprima/blob/master/src/token.ts#L14
function getTokenName(value: number): string {
switch (value) {
case Token.BooleanLiteral: return 'boolean' ...
default:
if (Token.Template === value) { return 'Template'; }
}
}
Note that I added a 'default' to the switch statement. This also to make V8 happy. V8 does not like switch without default and causing a perf loss.
This is all you need to do. Now you can replace the strict equal comparison - === - with this
Example
if (token.type === Token.Identifier) {}
has to be
if((token.type & Token.Identifier) !== 0) {}
To save space here you can create a helper function
function isNegativeBitmask(value) {
return (value & Token.Identifier) === 0)
}
function isPositiveBitmask(value) {
return (value & Token.Identifier) !== 0)
}
That's it. You will not break anything, and the benchmark results will be improved. And also V8 will be happy.
--