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.
Actually we don't use skipArrays anywhere. :)
There was a problem hiding this comment.
Can we just remove it then? :)
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
This comments can be removed, right?
There was a problem hiding this comment.
Change summary for future reviewers:
- Pack tokenizer boolean properties into bit flags
- The tokenizer state access
.lastTokStartis 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 #2The 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.