-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Switch let/const to var in the scanner & parser for top-levelish variables. #52832
Conversation
@typescript-bot perf test this faster |
Heya @DanielRosenwasser, I've started to run the abridged perf test suite on this PR at 450cfe1. You can monitor the build here. |
@typescript-bot perf test this faster |
Heya @DanielRosenwasser, I've started to run the abridged perf test suite on this PR at cd8b3a6. You can monitor the build here. Update: The results are in! |
@DanielRosenwasser Here they are:Comparison Report - main..52832
System
Hosts
Scenarios
Developer Information: |
Yay!!! |
Aside: is it just the scanner? Can we revert parser and test only the scanner? Is it a specific variable? That would be very interesting to know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1031,6 +1032,8 @@ export function createScanner(languageVersion: ScriptTarget, | |||
scanRange, | |||
}; | |||
|
|||
/* eslint-disable no-var */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by - was this maybe supposed to be eslint-enable
? It's already disabled above, and below there's no new var
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh, sure was!
This pull request regains some of the performance we lost in #51387 when we switched our emit from ES5 to ES2018 - a significant part due to TDZ checks that engines need to perform. These TDZ checks can often be eliminated, but engines probably have a hard time knowing whether a function can eliminate these checks.
By switching many of the top-level shared closure variables in the parser and scanner from
let
/const
tovar
, we're able to eliminate those checks. Doing so should be fairly safe, since our functions follow the same initialization mechanism of declaring variables, and then calling the "workhorse" function afterwards.