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 exceptions for control flow #9974
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10826/ |
this.state = state; | ||
return undefined; | ||
} | ||
|
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 is not nice, as we have this code now twice. But I see why you have done this.
What you should consider here is that cloning the state is also something that is more on the slow side, but not sure how it compares to throwing exceptions.
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.
Happy to merge as is.
if (this.eatRelational(">")) { | ||
return this.finishNode(node, "TSTypeParameterInstantiation"); | ||
} | ||
} |
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 lines 1478-1496 be shared with the tsParseTypeArguments
method?
a27047f
to
0c165e3
Compare
Now that #9989 has landed the optimizations here are not as urgent, so I have updated it to remove the If there is interest, I can change |
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.
Let's merge this for now, its better than before anyway.
PS. If you like perf optimizations, they are always welcome 😛
This commit optimizes the performance of the typescript parser plugin by avoiding exceptions for control flow. Currently, the typescript parser is filled with code branches that look something like this:
Throwing exceptions in node is expensive so this commit adds a few conditionals to avoid throwing where possible. The most common issue was related to type argument parsing, which had many false positives due to less-than binary expressions (eg
const y = x <
could beconst y = x <z>();
but it much more likely to beconst y = x < 10;
), so I added a newtsTryParseTypeArguments
that resets state and returnsundefined
instead of throwing.