-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Avoid allocating in updateLineCountAndPosFor #44241
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
Conversation
...(in the call to `computeLineStarts`) by detecting the very common case of not having a linebreak.
|
On my box, this cuts total time for the compiling ts/src by about 1% and I suspect it saves additional GC time in larger projects. |
|
@typescript-bot test this |
|
@typescript-bot perf test this |
|
Heya @amcasey, I've started to run the perf test suite on this PR at 22e2a80. You can monitor the build here. Update: The results are in! |
|
@amcasey Here they are:Comparison Report - master..44241
System
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
It is weird that Monaco and Compiler-Unions seems to see no improvement. |
| const lineStartsOfS = computeLineStarts(s); | ||
| if (lineStartsOfS.length > 1) { | ||
| // Most arguments don't contain one of JS's four linebreak characters | ||
| if (/[\r\n\u2028\u2029]/.test(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.
Drive by comment 🚗: I wonder if it could be beneficial to:
- Create the regex once
- Leverage the regex's
lastIndexinstead of usingcomputeLineStarts. This would involve iteratively matching to count the lines, then using the lastlastIndex+1 (and probably +2 for u2028/u2029) in favor oflast(lineStartsOfS).
(at which point it basically becomes a linear search just like computeLineStarts does, but without allocating the array. Maybe using a regex is not even needed)
Btw, lineStart = (linePos - output.length) === 0; a couple lines lower can just be lineStart = linePos === output.length; (probably won't make a difference).
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.
Thanks! If I don't abandon this in favor of #44242, I'll give that a shot (and, yeah, the === 0 was bugging me too).
|
This does not appear to have the same memory benefit as #44242. |
...(in the call to
computeLineStarts) by detecting the very common case of not having a linebreak.