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 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

@danez danez added area: perf PR: Polish 💅 A type of pull request used for our changelog categories pkg: parser labels Jan 16, 2019
@babel-bot
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
Copy link
Member

xtuc commented Jan 17, 2019

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

@danez
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 = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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..

Copy link
Member

@hzoo hzoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@danez danez merged commit 96a7343 into babel:master Jan 21, 2019
@danez danez deleted the perf branch January 21, 2019 10:27
@ef4
Copy link

ef4 commented Jan 22, 2019

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

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue 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.
Labels
area: perf outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Polish 💅 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants