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

Parser Performance Collection #9348

Merged
merged 21 commits into from Jan 21, 2019
Merged

Parser Performance Collection #9348

merged 21 commits into from Jan 21, 2019

Conversation

@danez
Copy link
Member

danez commented Jan 16, 2019

Q                       A
Fixed Issues?
Patch: Bug Fix? y
Major: Breaking Change? n
Minor: New Feature? n
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

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

@babel-bot

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Jan 16, 2019

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9816/

@xtuc

This comment has been minimized.

Copy link
Member

xtuc commented Jan 17, 2019

Really nice! Please let us know when it's ready for review.

@danez danez force-pushed the danez:perf branch from 6205e7c to 2d6231f Jan 18, 2019
@danez

This comment has been minimized.

Copy link
Member Author

danez commented Jan 18, 2019

I'm done now. Added some more changes, especially the keyword change brings some performance.


switch (env) {
// Configs used during bundling builds.
case "babel-parser":
convertESM = false;
ignoreLib = false;
envOpts.targets = {

This comment has been minimized.

Copy link
@hzoo

hzoo Jan 18, 2019

Member

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
hzoo approved these changes Jan 18, 2019
Copy link
Member

hzoo left a 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];

This comment has been minimized.

Copy link
@nicolo-ribaudo

nicolo-ribaudo Jan 18, 2019

Member

Just out of curiosity, what does flow complain about here?

This comment has been minimized.

Copy link
@danez

danez Jan 19, 2019

Author Member

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.

@@ -1630,7 +1631,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
this.match(tt.name) &&
(this.state.value === "type" ||
this.state.value === "interface" ||
this.state.value == "opaque")
this.state.value === "opaque")

This comment has been minimized.

Copy link
@nicolo-ribaudo

nicolo-ribaudo Jan 18, 2019

Member

We should enable the eslint rule to only allow == for null/undefined.

This comment has been minimized.

Copy link
@danez

danez Jan 19, 2019

Author Member

👍

Copy link
Member

nicolo-ribaudo left a comment

Looks good 👍

@danez danez merged commit 96a7343 into babel:master Jan 21, 2019
4 checks passed
4 checks passed
babel/repl REPL preview is available
Details
ci/circleci Your tests passed on CircleCI!
Details
codecov/project 80.67% (target 80%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@danez danez deleted the danez:perf branch Jan 21, 2019
@ef4

This comment has been minimized.

Copy link

ef4 commented Jan 22, 2019

The changes in this PR introduced a regression, see #9374.

@lock lock bot added the outdated label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants
You can’t perform that action at this time.