Skip to content
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

Port pyright optimization that skips loop flow nodes that dont contain relevant references #54460

Closed

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented May 30, 2023

Fixes #51525

This required reworking how we compare references so we could equate them within a set - that change, in and of itself, may actually also be perf positive (since we now get to cache the walk over the reference's AST), but both changes together is somewhere between neutral and 4% gains in local testing, depending on the suite. I'll need to see if this bears out on the much slower CI box, though, since 4% locally is < 0.1s, which is well in the realm of "OS scheduler variance" for some of these tests on my box. Do note, unlike pyright, which in the linked issue's change, calculates the references used within a loop during binding, we calculate it late on-demand and cache it in the checker. This is basically required for us, since we equate references using the identity of the resolved symbol of the root node of the reference (which... may be a bit circular with expression checking!). This means we don't get to collect the references for "free" while doing the binder AST walk; but given how often the set of references is referred to by control flow, it should probably still be an improvement in all but pathological cases (eg, thousands of references within a loop, none outside of it).

…n relevant references

Fixes microsoft#51525

This requied reworking how we compare references so we could equate them with a `set` - that change, in and of itself,
may actually also be perf positive (since we now get to cache the walk over the reference's AST), but both changes together
is somewhere between neutral and 4% gains in local testing, depending on the suite. I'll need to see if this bears out on
the much slower CI box, though, since 4% locally is < 0.1s, which is well in the realm of "OS scheduler variance" for some of these
tests on my box. Do note, unlike pyright, which in the linked issue's change, calculates the references used within a loop
during binding, we calculate it late on-demand and cache it in the checker. This is basically required for us, since we equate
references using the identity of the resolved symbol of the root node of the reference (which... may be a bit circular with
expression checking!).
@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels May 30, 2023
@weswigham
Copy link
Member Author

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented May 30, 2023

Heya @weswigham, I've started to run the perf test suite on this PR at b8a7bbe. You can monitor the build here.

Update: The results are in!

}

/**
* @returns A cache key that looks like `1234."field"."\"prop\".\"name\""` or `undefined` if the node can't be a reference
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is somewhat resilient against antagonistic field names, the escaping is potentially costly, and I'd like to try to avoid it if this shows promise. A less readable key format, like 1234.23.57 might be better (where 23 and 57 are indexes into a known-field-name-strings holding array). Still, I've cached the results, so it's not like we repeat the work, so savings by making this less readable aren't likely to be huge.

let references: ReadonlySet<never> | Set<string> = emptySet;
if (isStatement(node) || isExpressionNode(node)) {
// don't descend into variable declarations or binding elements, since those contain identifiers we don't want to collect
forEachChild(node, visitor);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The self-check failure points out that I need to swap this to use forEachChildRecursively (since that trampolines internally), since we allow binary expressions to nest greater than the max stack depth possible to traverse in the normal cached call/worker function used in the checker (because the parser is very stack depth efficient). That probably won't affect performance much.

I knew I'd need to do this, I didn't think we had hugely chained binary expressions in our own codebase, though - very much wondering which expressions are long enough to be an issue.

@DanielRosenwasser
Copy link
Member

This is basically required for us, since we equate references using the identity of the resolved symbol of the root node of the reference

Can you give an example of where this comes up? Is it for a computed reference like this?

const propName = "a";
obj[propName];

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - main..54460
Metric main 54460 Delta Best Worst p-value
Angular - node (v18.10.0, x64)
Memory used 365,818k (± 0.01%) 367,989k (± 0.01%) +2,170k (+ 0.59%) 367,957k 368,030k p=0.005 n=6
Parse Time 3.40s (± 0.49%) 3.41s (± 0.70%) ~ 3.37s 3.43s p=0.418 n=6
Bind Time 1.12s (± 0.73%) 1.11s (± 0.93%) ~ 1.10s 1.13s p=0.546 n=6
Check Time 8.72s (± 0.27%) 8.84s (± 0.27%) +0.11s (+ 1.32%) 8.81s 8.88s p=0.005 n=6
Emit Time 7.42s (± 0.55%) 7.41s (± 0.81%) ~ 7.35s 7.49s p=0.293 n=6
Total Time 20.66s (± 0.19%) 20.76s (± 0.43%) +0.10s (+ 0.47%) 20.67s 20.91s p=0.024 n=6
Compiler-Unions - node (v18.10.0, x64)
Memory used 191,135k (± 0.02%) 196,055k (± 0.04%) +4,921k (+ 2.57%) 195,981k 196,166k p=0.005 n=6
Parse Time 1.51s (± 0.69%) 1.51s (± 1.30%) ~ 1.49s 1.54s p=0.871 n=6
Bind Time 0.77s (± 0.00%) 0.77s (± 0.53%) ~ 0.77s 0.78s p=0.405 n=6
Check Time 9.47s (± 0.28%) 9.56s (± 0.32%) +0.09s (+ 0.99%) 9.52s 9.60s p=0.005 n=6
Emit Time 2.73s (± 1.29%) 2.72s (± 0.63%) ~ 2.70s 2.74s p=0.627 n=6
Total Time 14.48s (± 0.41%) 14.56s (± 0.39%) ~ 14.48s 14.64s p=0.065 n=6
Monaco - node (v18.10.0, x64)
Memory used 346,636k (± 0.01%) 352,832k (± 0.01%) +6,197k (+ 1.79%) 352,798k 352,909k p=0.005 n=6
Parse Time 2.61s (± 1.28%) 2.59s (± 0.66%) ~ 2.57s 2.61s p=0.164 n=6
Bind Time 1.02s (± 1.21%) 1.00s (± 0.51%) ~ 1.00s 1.01s p=0.101 n=6
Check Time 7.13s (± 0.49%) 7.31s (± 0.55%) +0.18s (+ 2.50%) 7.24s 7.35s p=0.005 n=6
Emit Time 4.25s (± 0.86%) 4.23s (± 0.71%) ~ 4.21s 4.29s p=0.627 n=6
Total Time 15.00s (± 0.38%) 15.14s (± 0.41%) +0.14s (+ 0.93%) 15.02s 15.20s p=0.015 n=6
TFS - node (v18.10.0, x64)
Memory used 300,634k (± 0.01%) 308,387k (± 0.01%) +7,754k (+ 2.58%) 308,360k 308,418k p=0.005 n=6
Parse Time 2.07s (± 1.31%) 2.06s (± 1.00%) ~ 2.03s 2.08s p=0.871 n=6
Bind Time 1.14s (± 0.55%) 1.14s (± 0.45%) ~ 1.13s 1.14s p=0.386 n=6
Check Time 6.62s (± 0.54%) 6.91s (± 0.67%) +0.29s (+ 4.41%) 6.84s 6.97s p=0.005 n=6
Emit Time 3.86s (± 0.87%) 3.87s (± 0.77%) ~ 3.82s 3.90s p=0.520 n=6
Total Time 13.69s (± 0.51%) 13.98s (± 0.45%) +0.30s (+ 2.17%) 13.90s 14.06s p=0.005 n=6
material-ui - node (v18.10.0, x64)
Memory used 481,709k (± 0.01%) 482,246k (± 0.01%) +537k (+ 0.11%) 482,207k 482,295k p=0.005 n=6
Parse Time 3.10s (± 0.44%) 3.10s (± 0.53%) ~ 3.08s 3.12s p=0.934 n=6
Bind Time 0.91s (± 1.65%) 0.91s (± 1.28%) ~ 0.90s 0.93s p=0.805 n=6
Check Time 16.76s (± 0.26%) 16.77s (± 0.24%) ~ 16.72s 16.82s p=1.000 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.79s (± 0.22%) 20.78s (± 0.18%) ~ 20.73s 20.84s p=0.936 n=6
xstate - node (v18.10.0, x64)
Memory used 562,987k (± 0.02%) 563,217k (± 0.02%) +230k (+ 0.04%) 563,098k 563,378k p=0.013 n=6
Parse Time 3.83s (± 0.60%) 3.81s (± 0.58%) ~ 3.79s 3.85s p=0.227 n=6
Bind Time 1.64s (± 0.77%) 1.64s (± 0.46%) ~ 1.63s 1.65s p=0.805 n=6
Check Time 2.82s (± 0.63%) 2.82s (± 0.84%) ~ 2.79s 2.85s p=1.000 n=6
Emit Time 0.08s (± 0.00%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=1.000 n=6
Total Time 8.38s (± 0.30%) 8.35s (± 0.27%) ~ 8.32s 8.39s p=0.142 n=6
Angular - node (v16.17.1, x64)
Memory used 365,231k (± 0.01%) 367,428k (± 0.01%) +2,198k (+ 0.60%) 367,392k 367,468k p=0.005 n=6
Parse Time 3.57s (± 0.61%) 3.56s (± 0.84%) ~ 3.53s 3.60s p=0.411 n=6
Bind Time 1.18s (± 0.46%) 1.18s (± 0.35%) ~ 1.17s 1.18s p=0.054 n=6
Check Time 9.58s (± 0.45%) 9.69s (± 0.32%) +0.10s (+ 1.08%) 9.64s 9.73s p=0.008 n=6
Emit Time 7.95s (± 0.91%) 7.92s (± 0.53%) ~ 7.87s 7.98s p=0.518 n=6
Total Time 22.29s (± 0.35%) 22.34s (± 0.37%) ~ 22.24s 22.49s p=0.521 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 192,897k (± 0.03%) 197,930k (± 0.04%) +5,033k (+ 2.61%) 197,761k 197,998k p=0.005 n=6
Parse Time 1.59s (± 2.05%) 1.58s (± 1.35%) ~ 1.55s 1.60s p=0.121 n=6
Bind Time 0.83s (± 0.62%) 0.82s (± 0.50%) -0.01s (- 1.40%) 0.82s 0.83s p=0.007 n=6
Check Time 10.27s (± 0.26%) 10.21s (± 0.40%) -0.06s (- 0.55%) 10.16s 10.26s p=0.029 n=6
Emit Time 3.01s (± 0.46%) 2.99s (± 0.81%) ~ 2.96s 3.03s p=0.073 n=6
Total Time 15.70s (± 0.35%) 15.60s (± 0.29%) -0.10s (- 0.64%) 15.55s 15.66s p=0.013 n=6
Monaco - node (v16.17.1, x64)
Memory used 345,884k (± 0.01%) 352,093k (± 0.00%) +6,208k (+ 1.79%) 352,065k 352,104k p=0.005 n=6
Parse Time 2.73s (± 0.43%) 2.73s (± 0.43%) ~ 2.71s 2.74s p=0.868 n=6
Bind Time 1.09s (± 0.95%) 1.09s (± 0.47%) ~ 1.08s 1.09s p=0.928 n=6
Check Time 7.84s (± 0.55%) 8.10s (± 0.36%) +0.25s (+ 3.23%) 8.06s 8.13s p=0.005 n=6
Emit Time 4.48s (± 0.86%) 4.48s (± 0.27%) ~ 4.46s 4.49s p=0.747 n=6
Total Time 16.14s (± 0.51%) 16.39s (± 0.23%) +0.25s (+ 1.57%) 16.34s 16.43s p=0.005 n=6
TFS - node (v16.17.1, x64)
Memory used 299,958k (± 0.01%) 307,706k (± 0.01%) +7,748k (+ 2.58%) 307,671k 307,722k p=0.005 n=6
Parse Time 2.16s (± 0.29%) 2.15s (± 0.64%) ~ 2.14s 2.18s p=0.236 n=6
Bind Time 1.24s (± 0.85%) 1.24s (± 0.44%) ~ 1.23s 1.24s p=1.000 n=6
Check Time 7.26s (± 0.41%) 7.63s (± 0.54%) +0.37s (+ 5.14%) 7.56s 7.68s p=0.005 n=6
Emit Time 4.34s (± 0.53%) 4.33s (± 0.52%) ~ 4.31s 4.36s p=0.936 n=6
Total Time 14.99s (± 0.22%) 15.35s (± 0.36%) +0.36s (+ 2.40%) 15.29s 15.42s p=0.005 n=6
material-ui - node (v16.17.1, x64)
Memory used 480,996k (± 0.01%) 481,495k (± 0.01%) +499k (+ 0.10%) 481,460k 481,522k p=0.005 n=6
Parse Time 3.25s (± 0.39%) 3.27s (± 0.59%) ~ 3.25s 3.30s p=0.087 n=6
Bind Time 0.94s (± 0.86%) 0.94s (± 0.58%) ~ 0.94s 0.95s p=0.441 n=6
Check Time 17.78s (± 0.33%) 17.88s (± 0.75%) ~ 17.75s 18.05s p=0.171 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 21.97s (± 0.29%) 22.09s (± 0.62%) ~ 21.96s 22.26s p=0.228 n=6
xstate - node (v16.17.1, x64)
Memory used 560,599k (± 0.02%) 560,763k (± 0.01%) +164k (+ 0.03%) 560,715k 560,897k p=0.045 n=6
Parse Time 4.00s (± 0.58%) 4.01s (± 0.43%) ~ 3.98s 4.03s p=0.326 n=6
Bind Time 1.76s (± 0.51%) 1.76s (± 0.46%) ~ 1.75s 1.77s p=0.550 n=6
Check Time 3.06s (± 0.57%) 3.08s (± 0.97%) ~ 3.04s 3.11s p=0.288 n=6
Emit Time 0.09s (± 0.00%) 0.09s (± 0.00%) ~ 0.09s 0.09s p=1.000 n=6
Total Time 8.90s (± 0.29%) 8.93s (± 0.42%) ~ 8.86s 8.97s p=0.076 n=6
Angular - node (v14.21.3, x64)
Memory used 359,207k (± 0.01%) 361,408k (± 0.01%) +2,201k (+ 0.61%) 361,378k 361,444k p=0.005 n=6
Parse Time 3.68s (± 0.65%) 3.66s (± 0.51%) ~ 3.64s 3.69s p=0.191 n=6
Bind Time 1.22s (± 0.62%) 1.21s (± 0.52%) ~ 1.20s 1.22s p=0.081 n=6
Check Time 9.99s (± 0.69%) 10.19s (± 0.40%) +0.19s (+ 1.92%) 10.13s 10.23s p=0.005 n=6
Emit Time 8.34s (± 0.89%) 8.38s (± 0.87%) ~ 8.27s 8.48s p=0.296 n=6
Total Time 23.23s (± 0.53%) 23.45s (± 0.43%) +0.21s (+ 0.91%) 23.27s 23.57s p=0.020 n=6
Compiler-Unions - node (v14.21.3, x64)
Memory used 188,284k (± 0.02%) 193,211k (± 0.01%) +4,927k (+ 2.62%) 193,168k 193,249k p=0.005 n=6
Parse Time 1.61s (± 0.55%) 1.61s (± 0.99%) ~ 1.60s 1.64s p=0.933 n=6
Bind Time 0.85s (± 0.74%) 0.85s (± 0.48%) ~ 0.84s 0.85s p=0.673 n=6
Check Time 10.31s (± 0.40%) 10.58s (± 0.44%) +0.27s (+ 2.57%) 10.51s 10.64s p=0.005 n=6
Emit Time 3.12s (± 0.83%) 3.11s (± 0.67%) ~ 3.09s 3.14s p=0.466 n=6
Total Time 15.90s (± 0.32%) 16.15s (± 0.24%) +0.25s (+ 1.57%) 16.09s 16.19s p=0.005 n=6
Monaco - node (v14.21.3, x64)
Memory used 341,016k (± 0.01%) 347,299k (± 0.01%) +6,284k (+ 1.84%) 347,247k 347,329k p=0.005 n=6
Parse Time 2.82s (± 1.07%) 2.81s (± 0.61%) ~ 2.79s 2.83s p=0.870 n=6
Bind Time 1.12s (± 0.75%) 1.11s (± 0.37%) ~ 1.11s 1.12s p=0.527 n=6
Check Time 8.22s (± 0.37%) 8.41s (± 0.38%) +0.18s (+ 2.23%) 8.38s 8.47s p=0.005 n=6
Emit Time 4.70s (± 0.43%) 4.67s (± 0.70%) ~ 4.64s 4.72s p=0.141 n=6
Total Time 16.86s (± 0.25%) 16.99s (± 0.32%) +0.14s (+ 0.82%) 16.93s 17.09s p=0.005 n=6
TFS - node (v14.21.3, x64)
Memory used 295,128k (± 0.01%) 302,855k (± 0.00%) +7,728k (+ 2.62%) 302,849k 302,859k p=0.005 n=6
Parse Time 2.40s (± 0.37%) 2.41s (± 0.92%) ~ 2.38s 2.44s p=0.677 n=6
Bind Time 1.07s (± 0.96%) 1.07s (± 0.78%) ~ 1.06s 1.08s p=0.672 n=6
Check Time 7.57s (± 0.37%) 7.92s (± 0.55%) +0.35s (+ 4.62%) 7.88s 7.98s p=0.005 n=6
Emit Time 4.34s (± 0.40%) 4.30s (± 0.76%) ~ 4.25s 4.33s p=0.084 n=6
Total Time 15.38s (± 0.32%) 15.71s (± 0.46%) +0.33s (+ 2.16%) 15.63s 15.82s p=0.005 n=6
material-ui - node (v14.21.3, x64)
Memory used 476,590k (± 0.00%) 477,044k (± 0.01%) +454k (+ 0.10%) 477,022k 477,092k p=0.005 n=6
Parse Time 3.36s (± 0.35%) 3.33s (± 0.41%) -0.02s (- 0.69%) 3.32s 3.35s p=0.023 n=6
Bind Time 1.01s (± 0.51%) 1.00s (± 0.00%) -0.01s (- 1.32%) 1.00s 1.00s p=0.002 n=6
Check Time 18.73s (± 0.62%) 18.76s (± 0.82%) ~ 18.49s 18.91s p=0.423 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 23.10s (± 0.48%) 23.09s (± 0.68%) ~ 22.82s 23.26s p=1.000 n=6
xstate - node (v14.21.3, x64)
Memory used 549,614k (± 0.00%) 549,759k (± 0.00%) +145k (+ 0.03%) 549,732k 549,793k p=0.005 n=6
Parse Time 4.23s (± 0.44%) 4.24s (± 0.51%) ~ 4.21s 4.27s p=0.167 n=6
Bind Time 1.62s (± 2.44%) 1.65s (± 2.80%) ~ 1.60s 1.71s p=0.146 n=6
Check Time 3.19s (± 0.65%) 3.19s (± 1.07%) ~ 3.13s 3.22s p=1.000 n=6
Emit Time 0.09s (± 0.00%) 0.09s (± 0.00%) ~ 0.09s 0.09s p=1.000 n=6
Total Time 9.13s (± 0.50%) 9.17s (± 0.82%) ~ 9.03s 9.25s p=0.173 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-148-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.21.3, x64)
Scenarios
  • Angular - node (v18.10.0, x64)
  • Angular - node (v16.17.1, x64)
  • Angular - node (v14.21.3, x64)
  • Compiler-Unions - node (v18.10.0, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Compiler-Unions - node (v14.21.3, x64)
  • Monaco - node (v18.10.0, x64)
  • Monaco - node (v16.17.1, x64)
  • Monaco - node (v14.21.3, x64)
  • TFS - node (v18.10.0, x64)
  • TFS - node (v16.17.1, x64)
  • TFS - node (v14.21.3, x64)
  • material-ui - node (v18.10.0, x64)
  • material-ui - node (v16.17.1, x64)
  • material-ui - node (v14.21.3, x64)
  • xstate - node (v18.10.0, x64)
  • xstate - node (v16.17.1, x64)
  • xstate - node (v14.21.3, x64)
Benchmark Name Iterations
Current 54460 6
Baseline main 6

TSServer

Comparison Report - main..54460
Metric main 54460 Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 2,528ms (± 0.49%) 2,538ms (± 0.78%) ~ 2,502ms 2,560ms p=0.229 n=6
Req 2 - geterr 5,542ms (± 0.44%) 5,768ms (± 0.81%) +226ms (+ 4.08%) 5,724ms 5,852ms p=0.005 n=6
Req 3 - references 338ms (± 0.89%) 343ms (± 2.05%) ~ 336ms 356ms p=0.124 n=6
Req 4 - navto 287ms (± 1.11%) 293ms (± 1.75%) +6ms (+ 2.03%) 286ms 298ms p=0.043 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 84ms (± 0.89%) 80ms (± 6.84%) ~ 75ms 86ms p=0.805 n=6
CompilerTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 2,639ms (± 0.60%) 2,640ms (± 0.50%) ~ 2,623ms 2,656ms p=0.936 n=6
Req 2 - geterr 4,285ms (± 0.35%) 4,404ms (± 0.23%) +119ms (+ 2.77%) 4,388ms 4,418ms p=0.005 n=6
Req 3 - references 348ms (± 0.82%) 354ms (± 0.15%) +6ms (+ 1.77%) 354ms 355ms p=0.004 n=6
Req 4 - navto 291ms (± 0.69%) 297ms (± 0.46%) +6ms (+ 2.18%) 295ms 299ms p=0.005 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 63ms (± 2.01%) 60ms (± 3.65%) 🟩-3ms (- 4.76%) 58ms 62ms p=0.025 n=6
xstateTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 3,081ms (± 0.50%) 3,079ms (± 0.45%) ~ 3,059ms 3,094ms p=0.809 n=6
Req 2 - geterr 1,568ms (± 0.71%) 1,583ms (± 1.49%) ~ 1,561ms 1,617ms p=0.199 n=6
Req 3 - references 114ms (± 1.47%) 115ms (± 2.01%) ~ 112ms 118ms p=0.418 n=6
Req 4 - navto 361ms (± 0.61%) 362ms (± 0.78%) ~ 358ms 364ms p=0.683 n=6
Req 5 - completionInfo count 2,862 (± 0.00%) 2,862 (± 0.00%) ~ 2,862 2,862 p=1.000 n=6
Req 5 - completionInfo 380ms (± 2.03%) 377ms (± 3.13%) ~ 365ms 394ms p=0.470 n=6
Compiler-UnionsTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,657ms (± 0.41%) 2,639ms (± 0.96%) ~ 2,612ms 2,675ms p=0.296 n=6
Req 2 - geterr 6,012ms (± 0.51%) 6,249ms (± 0.32%) +238ms (+ 3.95%) 6,217ms 6,272ms p=0.005 n=6
Req 3 - references 352ms (± 0.55%) 361ms (± 0.95%) +9ms (+ 2.51%) 356ms 366ms p=0.005 n=6
Req 4 - navto 286ms (± 0.79%) 287ms (± 1.36%) ~ 282ms 294ms p=0.869 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 90ms (± 5.11%) 92ms (± 2.04%) ~ 88ms 93ms p=0.615 n=6
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,832ms (± 0.15%) 2,835ms (± 0.87%) ~ 2,808ms 2,869ms p=1.000 n=6
Req 2 - geterr 4,638ms (± 0.34%) 4,798ms (± 0.63%) +160ms (+ 3.44%) 4,755ms 4,839ms p=0.005 n=6
Req 3 - references 365ms (± 0.95%) 368ms (± 0.66%) ~ 365ms 371ms p=0.124 n=6
Req 4 - navto 285ms (± 0.64%) 290ms (± 0.63%) +5ms (+ 1.64%) 287ms 291ms p=0.005 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 68ms (± 0.81%) 65ms (± 2.65%) 🟩-3ms (- 3.95%) 63ms 68ms p=0.032 n=6
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 3,212ms (± 0.55%) 3,220ms (± 0.79%) ~ 3,205ms 3,271ms p=0.748 n=6
Req 2 - geterr 1,737ms (± 0.77%) 1,739ms (± 1.14%) ~ 1,717ms 1,766ms p=1.000 n=6
Req 3 - references 124ms (± 0.51%) 134ms (± 7.54%) +10ms (+ 7.93%) 124ms 145ms p=0.024 n=6
Req 4 - navto 344ms (± 0.86%) 343ms (± 1.14%) ~ 340ms 351ms p=0.806 n=6
Req 5 - completionInfo count 2,862 (± 0.00%) 2,862 (± 0.00%) ~ 2,862 2,862 p=1.000 n=6
Req 5 - completionInfo 409ms (± 3.35%) 403ms (± 1.92%) ~ 394ms 414ms p=0.422 n=6
Compiler-UnionsTSServer - node (v14.21.3, x64)
Req 1 - updateOpen 2,799ms (± 0.65%) 2,786ms (± 0.30%) ~ 2,771ms 2,794ms p=0.108 n=6
Req 2 - geterr 6,236ms (± 0.51%) 6,364ms (± 0.31%) +128ms (+ 2.06%) 6,340ms 6,396ms p=0.005 n=6
Req 3 - references 363ms (± 0.45%) 364ms (± 1.14%) ~ 360ms 370ms p=0.871 n=6
Req 4 - navto 290ms (± 1.42%) 303ms (± 0.74%) +12ms (+ 4.25%) 300ms 305ms p=0.005 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 99ms (± 3.03%) 93ms (± 6.72%) ~ 85ms 99ms p=0.090 n=6
CompilerTSServer - node (v14.21.3, x64)
Req 1 - updateOpen 2,975ms (± 0.31%) 2,963ms (± 0.82%) ~ 2,938ms 2,992ms p=0.574 n=6
Req 2 - geterr 4,542ms (± 0.50%) 4,686ms (± 0.38%) +144ms (+ 3.18%) 4,666ms 4,715ms p=0.005 n=6
Req 3 - references 374ms (± 0.31%) 383ms (± 1.10%) +9ms (+ 2.27%) 375ms 387ms p=0.010 n=6
Req 4 - navto 299ms (± 0.27%) 293ms (± 0.34%) -6ms (- 1.95%) 291ms 294ms p=0.004 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 76ms (± 1.53%) 79ms (± 5.66%) ~ 76ms 88ms p=0.078 n=6
xstateTSServer - node (v14.21.3, x64)
Req 1 - updateOpen 3,511ms (± 1.40%) 3,514ms (± 0.86%) ~ 3,483ms 3,567ms p=1.000 n=6
Req 2 - geterr 1,845ms (± 0.59%) 1,856ms (± 0.83%) ~ 1,833ms 1,876ms p=0.199 n=6
Req 3 - references 150ms (± 7.97%) 152ms (± 6.57%) ~ 138ms 160ms p=0.747 n=6
Req 4 - navto 393ms (± 0.89%) 397ms (± 1.29%) ~ 391ms 405ms p=0.170 n=6
Req 5 - completionInfo count 2,862 (± 0.00%) 2,862 (± 0.00%) ~ 2,862 2,862 p=1.000 n=6
Req 5 - completionInfo 426ms (± 1.87%) 434ms (± 1.97%) ~ 424ms 445ms p=0.078 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-148-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.21.3, x64)
Scenarios
  • Compiler-UnionsTSServer - node (v18.10.0, x64)
  • Compiler-UnionsTSServer - node (v16.17.1, x64)
  • Compiler-UnionsTSServer - node (v14.21.3, x64)
  • CompilerTSServer - node (v18.10.0, x64)
  • CompilerTSServer - node (v16.17.1, x64)
  • CompilerTSServer - node (v14.21.3, x64)
  • xstateTSServer - node (v18.10.0, x64)
  • xstateTSServer - node (v16.17.1, x64)
  • xstateTSServer - node (v14.21.3, x64)
Benchmark Name Iterations
Current 54460 6
Baseline main 6

Startup

Comparison Report - main..54460
Metric main 54460 Delta Best Worst p-value
tsc-startup - node (v16.17.1, x64)
Execution time 141.23ms (± 0.15%) 141.87ms (± 0.21%) +0.64ms (+ 0.45%) 140.94ms 148.61ms p=0.000 n=600
tsserver-startup - node (v16.17.1, x64)
Execution time 220.08ms (± 0.18%) 220.37ms (± 0.26%) +0.29ms (+ 0.13%) 219.42ms 229.93ms p=0.000 n=600
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time 221.46ms (± 0.15%) 222.81ms (± 0.47%) +1.35ms (+ 0.61%) 221.45ms 234.06ms p=0.000 n=600
typescript-startup - node (v16.17.1, x64)
Execution time 203.34ms (± 0.16%) 204.00ms (± 0.13%) +0.66ms (+ 0.32%) 203.28ms 207.88ms p=0.000 n=600
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-148-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v16.17.1, x64)
Scenarios
  • tsc-startup - node (v16.17.1, x64)
  • tsserver-startup - node (v16.17.1, x64)
  • tsserverlibrary-startup - node (v16.17.1, x64)
  • typescript-startup - node (v16.17.1, x64)
Benchmark Name Iterations
Current 54460 6
Baseline main 6

Developer Information:

Download Benchmark

@weswigham
Copy link
Member Author

More like to support block scoped variable shadowing -

let x: 1 | 2 = 1;
x; // narrowed to `1`
{
  let x = 2
  x; // only the x within this block - `number`
}
x; // still `1`

which is probably the core reason it uses symbol identity for the roots and not lookup names, and then gets further complicated when the x is export (since that export can have other things merged into it by augmentations, so that identity can be changed by the symbol merging process). Presumably it's this way because it simplifies scope handling when comparing references, since you don't need to check that the references share the same scope or aren't being shadowed by a new reference.

It's mostly speculation on my part, since that's just how it's always been, at least as far as I've known. We've always compared symbols when looking at the root identifiers of references, and not the identifier text itself.

@weswigham
Copy link
Member Author

squints +5% in TFS, -1% in compiler-unions. OK, perf testing on my local machine is useless; results are nothing like the CI box. System noise is a lot worse when the tests run an order of magnitude faster. Guess I'm pushing all my iterations on this. Since there's a small perf improvement to compiler-unions - the test most likely to see improvements - this is likely a game to see if I can keep those improvements without a cost to the other suites. Then again, when you proposed this @DanielRosenwasser @jakebailey you were hoping for significantly more obvious gains? It's possible this work is only a minor improvement on top of the flow loop cache we already have in more normal code.

@jakebailey
Copy link
Member

i was hoping for obvious gains but my memory may be so poor that maybe this only manifests in examples with lots and lots of stuff going on.

will test with my own perf machine to verify as this is very weird

@typescript-bot perf test faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented May 30, 2023

Heya @jakebailey, I've started to run the abridged perf test suite on this PR at b8a7bbe. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..54460

Metric main 54460 Delta Best Worst p-value
Angular - node (v16.17.1, x64)
Memory used 365,231k (± 0.01%) 367,419k (± 0.01%) +2,188k (+ 0.60%) 367,373k 367,466k p=0.005 n=6
Parse Time 3.57s (± 0.61%) 3.56s (± 0.34%) ~ 3.54s 3.57s p=0.166 n=6
Bind Time 1.18s (± 0.46%) 1.18s (± 0.44%) -0.01s (- 0.70%) 1.17s 1.18s p=0.038 n=6
Check Time 9.58s (± 0.45%) 9.69s (± 0.49%) +0.10s (+ 1.08%) 9.62s 9.74s p=0.016 n=6
Emit Time 7.95s (± 0.91%) 7.98s (± 1.57%) ~ 7.84s 8.20s p=1.000 n=6
Total Time 22.29s (± 0.35%) 22.40s (± 0.72%) ~ 22.22s 22.66s p=0.336 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 192,897k (± 0.03%) 197,859k (± 0.05%) +4,962k (+ 2.57%) 197,774k 197,984k p=0.005 n=6
Parse Time 1.59s (± 2.05%) 1.59s (± 1.72%) ~ 1.54s 1.61s p=0.460 n=6
Bind Time 0.83s (± 0.62%) 0.83s (± 1.08%) ~ 0.82s 0.84s p=0.541 n=6
Check Time 10.27s (± 0.26%) 10.25s (± 0.67%) ~ 10.16s 10.33s p=0.684 n=6
Emit Time 3.01s (± 0.46%) 3.01s (± 1.13%) ~ 2.97s 3.06s p=0.807 n=6
Total Time 15.70s (± 0.35%) 15.67s (± 0.76%) ~ 15.52s 15.84s p=0.689 n=6
Monaco - node (v16.17.1, x64)
Memory used 345,884k (± 0.01%) 352,096k (± 0.00%) +6,212k (+ 1.80%) 352,084k 352,107k p=0.005 n=6
Parse Time 2.73s (± 0.43%) 2.73s (± 0.44%) ~ 2.72s 2.75s p=0.718 n=6
Bind Time 1.09s (± 0.95%) 1.08s (± 0.48%) ~ 1.08s 1.09s p=0.437 n=6
Check Time 7.84s (± 0.55%) 8.08s (± 0.50%) +0.24s (+ 3.08%) 8.03s 8.14s p=0.005 n=6
Emit Time 4.48s (± 0.86%) 4.46s (± 0.79%) ~ 4.41s 4.51s p=0.413 n=6
Total Time 16.14s (± 0.51%) 16.35s (± 0.45%) +0.21s (+ 1.33%) 16.26s 16.48s p=0.006 n=6
TFS - node (v16.17.1, x64)
Memory used 299,958k (± 0.01%) 307,725k (± 0.01%) +7,767k (+ 2.59%) 307,693k 307,754k p=0.005 n=6
Parse Time 2.16s (± 0.29%) 2.16s (± 0.81%) ~ 2.15s 2.19s p=0.866 n=6
Bind Time 1.24s (± 0.85%) 1.24s (± 0.42%) ~ 1.23s 1.24s p=0.794 n=6
Check Time 7.26s (± 0.41%) 7.60s (± 0.58%) +0.34s (+ 4.75%) 7.56s 7.67s p=0.005 n=6
Emit Time 4.34s (± 0.53%) 4.35s (± 0.83%) ~ 4.29s 4.39s p=0.469 n=6
Total Time 14.99s (± 0.22%) 15.36s (± 0.36%) +0.37s (+ 2.43%) 15.28s 15.44s p=0.005 n=6
material-ui - node (v16.17.1, x64)
Memory used 480,996k (± 0.01%) 481,505k (± 0.01%) +509k (+ 0.11%) 481,452k 481,551k p=0.005 n=6
Parse Time 3.25s (± 0.39%) 3.25s (± 0.41%) ~ 3.23s 3.27s p=0.742 n=6
Bind Time 0.94s (± 0.86%) 0.94s (± 0.67%) ~ 0.93s 0.95s p=0.599 n=6
Check Time 17.78s (± 0.33%) 17.89s (± 0.47%) +0.12s (+ 0.68%) 17.80s 18.02s p=0.030 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 21.97s (± 0.29%) 22.09s (± 0.37%) +0.12s (+ 0.55%) 21.99s 22.19s p=0.024 n=6
xstate - node (v16.17.1, x64)
Memory used 560,599k (± 0.02%) 560,828k (± 0.02%) +229k (+ 0.04%) 560,700k 561,022k p=0.031 n=6
Parse Time 4.00s (± 0.58%) 4.00s (± 0.37%) ~ 3.98s 4.02s p=0.686 n=6
Bind Time 1.76s (± 0.51%) 1.76s (± 0.56%) ~ 1.75s 1.77s p=0.798 n=6
Check Time 3.06s (± 0.57%) 3.05s (± 0.78%) ~ 3.02s 3.09s p=0.510 n=6
Emit Time 0.09s (± 0.00%) 0.09s (± 0.00%) ~ 0.09s 0.09s p=1.000 n=6
Total Time 8.90s (± 0.29%) 8.90s (± 0.33%) ~ 8.87s 8.95s p=0.686 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-148-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v16.17.1, x64)
Scenarios
  • Angular - node (v16.17.1, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Monaco - node (v16.17.1, x64)
  • TFS - node (v16.17.1, x64)
  • material-ui - node (v16.17.1, x64)
  • xstate - node (v16.17.1, x64)
Benchmark Name Iterations
Current 54460 6
Baseline main 6

Developer Information:

Download Benchmark

@weswigham
Copy link
Member Author

I haven't gotten any version of this to have an outsized, consistent effect locally on our test suite; I'm going to assume our existing flow loop cache largely subsumes this, making it much less impactful.

@weswigham weswigham closed this Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Experiment with tracking which entities actually may be narrowed
4 participants