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
perf: Improve parser performance for typescript #16072
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/56117/ |
9289115
to
cbd7bd8
Compare
|
c8b3fc8
to
f1f8472
Compare
@@ -152,20 +279,36 @@ export default class State { | |||
} | |||
|
|||
clone(skipArrays?: boolean): State { |
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.
Actually we don't use skipArrays
anywhere. :)
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.
Can we just remove it then? :)
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.
I think given how popular TS is, the perf change is ok.
state.context = maybeCopy(this.context); | ||
state.firstInvalidTemplateEscapePos = this.firstInvalidTemplateEscapePos; | ||
state.strictErrors = this.strictErrors; | ||
state.tokensLength = this.tokensLength; |
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.
Do you think we can somehow type-check this list to make sure we don't forget to add props? If not, can you add a comment at the beginning of State
's body saying that when adding a new property we must also add it here?
const { commentsLen } = this.state; | ||
if (this.comments.length != commentsLen) this.comments.length = commentsLen; | ||
this.comments.push(comment); | ||
this.state.commentsLen++; |
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.
Can it happen that we clone the state, push a comment to .comments
, reset to the previous state, then never call .addComment
again and so we never do this.comments.length = commentsLen
removing the new extra comment?
b6cbd7e
to
0a3ef44
Compare
0a3ef44
to
21c6cd7
Compare
21c6cd7
to
5958911
Compare
5958911
to
16284ce
Compare
@@ -152,20 +279,36 @@ export default class State { | |||
} | |||
|
|||
clone(skipArrays?: boolean): State { |
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.
Can we just remove it then? :)
// In strict mode, scope.functions will always be empty. | ||
// Modules are strict by default, but the `scriptMode` option | ||
// can overwrite this behavior. |
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.
This comments can be removed, right?
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.
Change summary for future reviewers:
- Pack tokenizer boolean properties into bit flags
- The tokenizer state access
.lastTokStart
is replaced by.lastTokStartLoc.index
- Replace
.raise({ at })
by.raise(at)
to reduce cost of intermediate object literal - Specify each state properties in parser state clone to avoid dynamic property access
- Merge multiple names set in parser scope tracker into a map
16284ce
to
985dc49
Compare
Fixes #1, Fixes #2
The ts parsing time is reduced by ~20%, and the general js parsing time is increased by ~2%.
If we want general js not to be affected, maybe we can manually replace all
getters/setters
.