Parser Performance Collection#9348
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9816/ |
|
Really nice! Please let us know when it's ready for review. |
This also fixes a bug with async functions
Fix plugin options
This avoids checking isIdentifierStart for every single token
This saves some steps, as the regex parser does not have to backtrack for character classes, but is has to for alternates
It does a lot of checks and a regex test
Instead of calling isKeyword we simple check directly if the keyword token is available
|
I'm done now. Added some more changes, especially the keyword change brings some performance. |
| case "babel-parser": | ||
| convertESM = false; | ||
| ignoreLib = false; | ||
| envOpts.targets = { |
There was a problem hiding this comment.
It's possible we didn't add this before since Babylon was in another repo and a different config? Or I think it was actually slower before? Or it was because of browser support..
hzoo
left a comment
There was a problem hiding this comment.
great changes, yeah object -> map/set is good
There was a reason for the parser thing but it's probably browser compat
| getPluginOption(plugin: string, name: string) { | ||
| if (this.hasPlugin(plugin)) return this.plugins[plugin][name]; | ||
| // $FlowIssue | ||
| if (this.hasPlugin(plugin)) return this.plugins.get(plugin)[name]; |
There was a problem hiding this comment.
Just out of curiosity, what does flow complain about here?
There was a problem hiding this comment.
It is because of this: facebook/flow#2751
Flow does not realize that calling has ensures that get will return something !=null
Other way would be just calling get and testing if != null.
| (this.state.value === "type" || | ||
| this.state.value === "interface" || | ||
| this.state.value == "opaque") | ||
| this.state.value === "opaque") |
There was a problem hiding this comment.
We should enable the eslint rule to only allow == for null/undefined.
|
The changes in this PR introduced a regression, see #9374. |
So I tried to work on performance in the parser. I did not have any ground breaking success but found some small and minor stuff here and there.
Some of the changes might be debatable. If something feels weird to any of you feel free to mention and I can remove it.
The most impactful change here (depending on the tested source of course) is the removal of flow code from the regular parser. (Only if not using the flow plugin)
The other big improvement is compiling the parser for node 6.9 or newer only. I was surprised to see it was using all transforms. This might be a problem if someone is using the parser in an older browser without first compiling.
Overall it is a tiny bit noticeable but most changes also add to readability and understanding the code.
The changes are separated into commits to make it easier to see what belongs together.
I also tried other things like exchanging the big switch-case for an object as hashmap, but that made no difference.
I also updated the benchmark tool to work better and more consistently. babel/parser_performance@1df708c