Skip to content

Conversation

@amcasey
Copy link
Member

@amcasey amcasey commented May 24, 2021

...(in the call to computeLineStarts) by detecting the very common case of not having a linebreak.

...(in the call to `computeLineStarts`) by detecting the very common
case of not having a linebreak.
@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels May 24, 2021
@amcasey
Copy link
Member Author

amcasey commented May 24, 2021

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.

@amcasey
Copy link
Member Author

amcasey commented May 24, 2021

@typescript-bot test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented May 24, 2021

Heya @amcasey, I've started to run the extended test suite on this PR at 22e2a80. You can monitor the build here.

@amcasey
Copy link
Member Author

amcasey commented May 24, 2021

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented May 24, 2021

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!

@typescript-bot
Copy link
Collaborator

@amcasey
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..44241

Metric master 44241 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 343,936k (± 0.03%) 343,918k (± 0.02%) -18k (- 0.01%) 343,820k 344,027k
Parse Time 1.79s (± 0.46%) 1.80s (± 0.44%) +0.00s (+ 0.17%) 1.77s 1.81s
Bind Time 0.84s (± 0.44%) 0.84s (± 0.88%) +0.00s (+ 0.48%) 0.82s 0.85s
Check Time 5.21s (± 0.41%) 5.20s (± 0.32%) -0.01s (- 0.27%) 5.17s 5.23s
Emit Time 5.46s (± 0.48%) 5.48s (± 0.40%) +0.02s (+ 0.37%) 5.43s 5.52s
Total Time 13.31s (± 0.31%) 13.32s (± 0.33%) +0.01s (+ 0.09%) 13.21s 13.39s
Compiler-Unions - node (v10.16.3, x64)
Memory used 200,377k (± 0.07%) 200,310k (± 0.05%) -67k (- 0.03%) 200,022k 200,512k
Parse Time 0.78s (± 0.75%) 0.78s (± 0.79%) +0.00s (+ 0.26%) 0.77s 0.79s
Bind Time 0.53s (± 1.44%) 0.53s (± 1.90%) +0.00s (+ 0.19%) 0.50s 0.55s
Check Time 7.50s (± 0.51%) 7.54s (± 0.36%) +0.04s (+ 0.51%) 7.50s 7.63s
Emit Time 2.23s (± 1.17%) 2.25s (± 0.96%) +0.01s (+ 0.63%) 2.20s 2.30s
Total Time 11.04s (± 0.34%) 11.09s (± 0.43%) +0.05s (+ 0.44%) 11.03s 11.23s
Monaco - node (v10.16.3, x64)
Memory used 340,427k (± 0.02%) 340,428k (± 0.02%) +2k (+ 0.00%) 340,306k 340,532k
Parse Time 1.46s (± 0.61%) 1.45s (± 0.73%) -0.01s (- 0.62%) 1.43s 1.47s
Bind Time 0.74s (± 0.67%) 0.74s (± 1.49%) +0.01s (+ 0.95%) 0.73s 0.78s
Check Time 5.38s (± 0.42%) 5.37s (± 0.50%) -0.01s (- 0.26%) 5.29s 5.41s
Emit Time 2.96s (± 0.94%) 2.97s (± 0.70%) +0.01s (+ 0.27%) 2.92s 3.01s
Total Time 10.54s (± 0.39%) 10.53s (± 0.41%) -0.01s (- 0.10%) 10.40s 10.59s
TFS - node (v10.16.3, x64)
Memory used 303,989k (± 0.01%) 303,961k (± 0.03%) -28k (- 0.01%) 303,745k 304,132k
Parse Time 1.18s (± 0.57%) 1.18s (± 0.75%) 0.00s ( 0.00%) 1.16s 1.20s
Bind Time 0.70s (± 0.70%) 0.71s (± 0.73%) +0.01s (+ 0.71%) 0.70s 0.72s
Check Time 4.88s (± 0.54%) 4.85s (± 0.43%) -0.03s (- 0.57%) 4.81s 4.89s
Emit Time 3.10s (± 1.33%) 2.92s (± 1.41%) 🟩-0.18s (- 5.80%) 2.86s 3.03s
Total Time 9.86s (± 0.69%) 9.66s (± 0.56%) -0.20s (- 2.01%) 9.53s 9.79s
material-ui - node (v10.16.3, x64)
Memory used 471,577k (± 0.01%) 471,563k (± 0.01%) -14k (- 0.00%) 471,470k 471,696k
Parse Time 1.72s (± 0.46%) 1.72s (± 0.20%) -0.01s (- 0.29%) 1.71s 1.72s
Bind Time 0.66s (± 0.98%) 0.66s (± 0.45%) -0.00s (- 0.60%) 0.65s 0.66s
Check Time 14.19s (± 0.54%) 14.11s (± 0.19%) -0.07s (- 0.53%) 14.05s 14.18s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.57s (± 0.49%) 16.49s (± 0.16%) -0.08s (- 0.50%) 16.43s 16.56s
Angular - node (v12.1.0, x64)
Memory used 322,155k (± 0.04%) 322,110k (± 0.03%) -46k (- 0.01%) 321,879k 322,317k
Parse Time 1.77s (± 0.53%) 1.78s (± 0.73%) +0.00s (+ 0.17%) 1.75s 1.80s
Bind Time 0.83s (± 0.92%) 0.83s (± 1.14%) +0.00s (+ 0.12%) 0.81s 0.85s
Check Time 5.08s (± 0.61%) 5.08s (± 0.37%) -0.01s (- 0.12%) 5.03s 5.12s
Emit Time 5.68s (± 0.64%) 5.70s (± 0.72%) +0.01s (+ 0.25%) 5.59s 5.79s
Total Time 13.37s (± 0.41%) 13.38s (± 0.41%) +0.01s (+ 0.09%) 13.26s 13.51s
Compiler-Unions - node (v12.1.0, x64)
Memory used 187,739k (± 0.07%) 187,682k (± 0.11%) -57k (- 0.03%) 187,130k 187,954k
Parse Time 0.77s (± 0.78%) 0.77s (± 0.65%) -0.00s (- 0.13%) 0.76s 0.78s
Bind Time 0.53s (± 0.90%) 0.53s (± 0.63%) +0.00s (+ 0.57%) 0.52s 0.54s
Check Time 7.02s (± 0.51%) 7.02s (± 0.57%) -0.00s (- 0.04%) 6.95s 7.15s
Emit Time 2.26s (± 0.92%) 2.23s (± 0.74%) -0.02s (- 1.11%) 2.20s 2.28s
Total Time 10.57s (± 0.44%) 10.54s (± 0.37%) -0.03s (- 0.25%) 10.45s 10.64s
Monaco - node (v12.1.0, x64)
Memory used 323,453k (± 0.02%) 323,508k (± 0.02%) +55k (+ 0.02%) 323,352k 323,593k
Parse Time 1.42s (± 0.94%) 1.41s (± 0.88%) -0.01s (- 0.42%) 1.38s 1.43s
Bind Time 0.71s (± 0.95%) 0.71s (± 0.48%) -0.00s (- 0.14%) 0.71s 0.72s
Check Time 5.18s (± 0.44%) 5.19s (± 0.46%) +0.01s (+ 0.19%) 5.15s 5.25s
Emit Time 2.99s (± 0.51%) 3.00s (± 0.74%) +0.01s (+ 0.40%) 2.95s 3.05s
Total Time 10.30s (± 0.24%) 10.32s (± 0.44%) +0.02s (+ 0.18%) 10.21s 10.45s
TFS - node (v12.1.0, x64)
Memory used 288,573k (± 0.01%) 288,559k (± 0.03%) -14k (- 0.00%) 288,448k 288,752k
Parse Time 1.18s (± 0.63%) 1.18s (± 0.86%) -0.00s (- 0.17%) 1.16s 1.21s
Bind Time 0.69s (± 1.22%) 0.69s (± 0.72%) -0.00s (- 0.44%) 0.68s 0.70s
Check Time 4.77s (± 0.34%) 4.77s (± 0.77%) +0.01s (+ 0.15%) 4.71s 4.87s
Emit Time 3.12s (± 0.60%) 3.01s (± 0.80%) 🟩-0.11s (- 3.43%) 2.97s 3.08s
Total Time 9.75s (± 0.39%) 9.65s (± 0.59%) -0.10s (- 1.07%) 9.54s 9.78s
material-ui - node (v12.1.0, x64)
Memory used 450,296k (± 0.01%) 450,217k (± 0.05%) -78k (- 0.02%) 449,275k 450,402k
Parse Time 1.72s (± 0.64%) 1.71s (± 0.45%) -0.01s (- 0.52%) 1.69s 1.73s
Bind Time 0.64s (± 1.01%) 0.64s (± 0.87%) +0.00s (+ 0.00%) 0.63s 0.65s
Check Time 12.73s (± 0.54%) 12.76s (± 0.60%) +0.04s (+ 0.29%) 12.68s 13.00s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.08s (± 0.44%) 15.11s (± 0.47%) +0.03s (+ 0.19%) 15.03s 15.34s
Angular - node (v14.15.1, x64)
Memory used 320,863k (± 0.01%) 320,883k (± 0.01%) +21k (+ 0.01%) 320,853k 320,915k
Parse Time 1.79s (± 0.71%) 1.79s (± 0.65%) -0.00s (- 0.06%) 1.77s 1.82s
Bind Time 0.87s (± 1.31%) 0.86s (± 0.43%) -0.01s (- 0.80%) 0.86s 0.87s
Check Time 5.09s (± 0.31%) 5.12s (± 0.60%) +0.02s (+ 0.45%) 5.06s 5.19s
Emit Time 5.72s (± 0.49%) 5.82s (± 0.65%) +0.10s (+ 1.71%) 5.76s 5.91s
Total Time 13.47s (± 0.28%) 13.59s (± 0.44%) +0.12s (+ 0.87%) 13.48s 13.76s
Compiler-Unions - node (v14.15.1, x64)
Memory used 188,830k (± 0.58%) 189,430k (± 0.37%) +601k (+ 0.32%) 186,599k 189,877k
Parse Time 0.80s (± 0.81%) 0.80s (± 0.59%) +0.00s (+ 0.25%) 0.79s 0.81s
Bind Time 0.55s (± 0.40%) 0.55s (± 0.90%) +0.00s (+ 0.73%) 0.55s 0.57s
Check Time 7.13s (± 0.46%) 7.13s (± 0.55%) -0.00s (- 0.04%) 7.04s 7.20s
Emit Time 2.25s (± 0.61%) 2.29s (± 0.70%) +0.04s (+ 1.73%) 2.26s 2.34s
Total Time 10.73s (± 0.27%) 10.77s (± 0.40%) +0.04s (+ 0.37%) 10.66s 10.84s
Monaco - node (v14.15.1, x64)
Memory used 322,503k (± 0.01%) 322,523k (± 0.01%) +20k (+ 0.01%) 322,470k 322,558k
Parse Time 1.46s (± 0.72%) 1.46s (± 0.44%) +0.01s (+ 0.34%) 1.45s 1.48s
Bind Time 0.74s (± 0.40%) 0.75s (± 0.89%) +0.01s (+ 0.67%) 0.74s 0.77s
Check Time 5.16s (± 0.40%) 5.18s (± 0.49%) +0.02s (+ 0.43%) 5.13s 5.24s
Emit Time 3.06s (± 0.64%) 3.12s (± 0.63%) +0.06s (+ 1.93%) 3.09s 3.17s
Total Time 10.41s (± 0.36%) 10.51s (± 0.22%) +0.09s (+ 0.90%) 10.45s 10.56s
TFS - node (v14.15.1, x64)
Memory used 287,603k (± 0.00%) 287,577k (± 0.01%) -26k (- 0.01%) 287,544k 287,627k
Parse Time 1.24s (± 1.48%) 1.25s (± 1.61%) +0.00s (+ 0.24%) 1.22s 1.32s
Bind Time 0.71s (± 0.63%) 0.71s (± 0.83%) +0.00s (+ 0.28%) 0.70s 0.73s
Check Time 4.80s (± 0.67%) 4.81s (± 0.50%) +0.00s (+ 0.10%) 4.76s 4.86s
Emit Time 3.21s (± 0.83%) 3.09s (± 1.14%) 🟩-0.12s (- 3.71%) 3.04s 3.21s
Total Time 9.96s (± 0.56%) 9.85s (± 0.39%) -0.11s (- 1.06%) 9.78s 9.96s
material-ui - node (v14.15.1, x64)
Memory used 448,638k (± 0.00%) 448,453k (± 0.06%) -185k (- 0.04%) 447,523k 448,656k
Parse Time 1.77s (± 0.38%) 1.77s (± 0.68%) -0.01s (- 0.39%) 1.74s 1.79s
Bind Time 0.69s (± 0.58%) 0.69s (± 0.32%) 0.00s ( 0.00%) 0.68s 0.69s
Check Time 12.90s (± 0.37%) 12.96s (± 0.67%) +0.06s (+ 0.47%) 12.82s 13.26s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.36s (± 0.30%) 15.42s (± 0.54%) +0.06s (+ 0.36%) 15.28s 15.70s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory1 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
Benchmark Name Iterations
Current 44241 10
Baseline master 10

Developer Information:

Download Benchmark

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented May 24, 2021

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)) {
Copy link
Contributor

@JoostK JoostK May 24, 2021

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:

  1. Create the regex once
  2. Leverage the regex's lastIndex instead of using computeLineStarts. This would involve iteratively matching to count the lines, then using the last lastIndex +1 (and probably +2 for u2028/u2029) in favor of last(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).

Copy link
Member Author

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).

@amcasey
Copy link
Member Author

amcasey commented May 25, 2021

This does not appear to have the same memory benefit as #44242.

@amcasey amcasey closed this May 25, 2021
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants