-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Don't slice whitespace in jsdoc parser unless needed #53121
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
Don't slice whitespace in jsdoc parser unless needed #53121
Conversation
It's only needed when there's an indentation relative to the margin, which is rare. The common case is to skip the whitespace.
@typescript-bot perf test this |
Heya @sandersn, I've started to run the perf test suite on this PR at 000f7a5. You can monitor the build here. Update: The results are in! |
@sandersn Here they are:
CompilerComparison Report - main..53121
System
Hosts
Scenarios
TSServerComparison Report - main..53121
System
Hosts
Scenarios
StartupComparison Report - main..53121
System
Hosts
Scenarios
Developer Information: |
src/compiler/parser.ts
Outdated
if (margin !== undefined && indent + whitespace.length > margin) { | ||
comments.push(whitespace.slice(margin - indent)); | ||
if (margin !== undefined && indent + whitespaceLength > margin) { | ||
comments.push(scanner.getTokenText().slice(margin - indent)); |
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.
Well, I would've said not to do the double-substring
/slice
- but at this point I'm skeptical that it will affect perf much.
By the way, what is this logic trying to model?
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.
When you write
/**
* Some comments here
* Blockquote here
* And here
* Back to original indentation
*/
The two blockquoted lines need to include 4 of the 5 spaces after the asterisk. Conversely, the first and last lines should skip the 1 space after the asterisk.
Needing to slice additional whitespace for the margin is uncommon, so putting the slice only in that branch should have improved performance noticeably. I'm not sure why it didn't.
From my other experiment. Maybe together they'll be fast!
@typescript-bot perf test this |
Heya @sandersn, I've started to run the perf test suite on this PR at 794b0f3. You can monitor the build here. Update: The results are in! |
@sandersn Here they are:
CompilerComparison Report - main..53121
System
Hosts
Scenarios
TSServerComparison Report - main..53121
System
Hosts
Scenarios
StartupComparison Report - main..53121
System
Hosts
Scenarios
Developer Information: |
Well, two barely slow things together are still barely slow. Oh well. |
It's only needed when there's an indentation relative to the margin, which is rare and usually doesn't last for the entire comment text. The common case is to skip the whitespace.
Edit: I also included the code to scan the initial
*
indent as whitespace just in case two slightly-slow things combined might be faster together 🤷🏼Works on #52959, based on a suggestion from @DanielRosenwasser in #53081