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

Avoid unnecessary work during lookahead #9982

Merged
merged 3 commits into from May 16, 2019
Merged

Avoid unnecessary work during lookahead #9982

merged 3 commits into from May 16, 2019

Conversation

danez
Copy link
Member

@danez danez commented May 15, 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

We were create a comment object but not doing anything with it. Then I noticed that even calling pushComment() is unnecessary and this way we avoid some slicing on the input.

Also we were calling updateContext() during lookahead which potentially could add a new context to the state, but as we do not clone arrays in state during lookahead this would mess up the state.
And we always only check the type or the value on the lookahead state.

And because we do no call updateContext() anymore I don't think we need to clone this.state.context every time, because it won't be change during lookahead.

I did not see any noticeable performance change, but we are doing lookahead() mostly in flow/ts plugins which I haven't tested.

@danez danez added PR: Polish 💅 A type of pull request used for our changelog categories pkg: parser labels May 15, 2019
@babel-bot
Copy link
Collaborator

babel-bot commented May 15, 2019

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

@danez danez added PR: Bug Fix 🐛 A type of pull request used for our changelog categories and removed PR: Polish 💅 A type of pull request used for our changelog categories pkg: parser labels May 15, 2019
@danez danez changed the title Do not call pushComment when doing lookahead Avoid unnecessary work during lookahead May 15, 2019
@danez
Copy link
Member Author

danez commented May 16, 2019

This is slightly faster with the fixture doing 30 dynamic imports (because I know there was one lookahead there). #9983 is not included.

❯ node --expose-gc --max-old-space-size=2000 --max-semi-space-size=1500 --noconcurrent_sweeping index.js
Node: v12.2.0
Running benchmark for es6/import.js ...
┌───────────────┬───────────────────────────────┬───────────────────────────────┐
│ fixture       │ babel                         │ babelNew                      │
├───────────────┼───────────────────────────────┼───────────────────────────────┤
│ es6/import.js │ 6100 ops/sec ±0.69% (0.164ms) │ 6358 ops/sec ±0.34% (0.157ms) │
└───────────────┴───────────────────────────────┴───────────────────────────────┘

@danez danez merged commit 4da7a01 into babel:master May 16, 2019
@danez danez deleted the fix-comments branch May 16, 2019 00:02
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 3, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 3, 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: Bug Fix 🐛 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

4 participants