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

Experimental variant on #57465 with two optimizations #57660

Closed
wants to merge 29 commits into from

Conversation

danvk
Copy link
Contributor

@danvk danvk commented Mar 6, 2024

This adds two optimizations to #57465:

  • For the false check, if trueType is a large union (20+ constituents) then split it into two chunks when calling getFlowTypeOfReference. The first chunk has the first 10 types, the second has the remainder. If the first chunk doesn't narrow to never then we don't have to check the second. This is a huge win on Use union types for all common classes of AST nodes #54148. On my laptop it reduces the time for the most extreme check from 312ms→140ms by only checking 10/112 types in the union. There are several other expensive calls on that PR that it's able to bypass as well. This has less of an effect on the Compiler-Unions benchmark.
  • A fast path for functions of the form x => x === y (or ==, !==, !=). These can only be type predicates if y is a unit type like null or undefined, but that can be expensive to determine via the usual calls to getFlowTypeOfReference if x and y are both large union types. In both Compiler-Unions and Use union types for all common classes of AST nodes #54148 there are some expensive checks that this bypasses, notably d => d === objectLiteralDeclaration.

In local testing these help on both Compiler-Unions and #54148. The x === y optimization is definitely targeted at a specific case in Compiler-Unions, but it's a win on #54148 as well, so perhaps it does generalize.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Mar 6, 2024
@jakebailey
Copy link
Member

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 6, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
perf test this ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

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

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v18.15.0, x64)
Memory used 295,565k (± 0.00%) 295,585k (± 0.01%) ~ 295,516k 295,620k p=0.230 n=6
Parse Time 2.66s (± 0.28%) 2.66s (± 0.51%) ~ 2.64s 2.67s p=0.672 n=6
Bind Time 0.83s (± 0.62%) 0.83s (± 0.76%) ~ 0.82s 0.84s p=0.386 n=6
Check Time 8.22s (± 0.18%) 8.21s (± 0.37%) ~ 8.19s 8.27s p=0.415 n=6
Emit Time 7.10s (± 0.43%) 7.10s (± 0.19%) ~ 7.08s 7.12s p=0.806 n=6
Total Time 18.81s (± 0.14%) 18.80s (± 0.14%) ~ 18.77s 18.84s p=0.627 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 192,120k (± 0.73%) 192,445k (± 0.71%) +325k (+ 0.17%) 191,772k 195,220k p=0.045 n=6
Parse Time 1.35s (± 0.98%) 1.37s (± 1.01%) ~ 1.35s 1.38s p=0.156 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.36s (± 0.50%) 9.52s (± 0.32%) +0.16s (+ 1.71%) 9.47s 9.55s p=0.005 n=6
Emit Time 2.61s (± 0.66%) 2.61s (± 0.78%) ~ 2.59s 2.64s p=0.870 n=6
Total Time 14.04s (± 0.35%) 14.22s (± 0.22%) +0.18s (+ 1.26%) 14.17s 14.26s p=0.005 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,339k (± 0.00%) 347,384k (± 0.00%) +45k (+ 0.01%) 347,370k 347,395k p=0.005 n=6
Parse Time 2.48s (± 0.42%) 2.48s (± 0.47%) ~ 2.47s 2.50s p=0.801 n=6
Bind Time 0.93s (± 0.56%) 0.93s (± 0.56%) ~ 0.92s 0.93s p=1.000 n=6
Check Time 6.97s (± 0.34%) 6.99s (± 0.34%) ~ 6.95s 7.02s p=0.056 n=6
Emit Time 4.06s (± 0.31%) 4.09s (± 0.33%) +0.03s (+ 0.66%) 4.07s 4.11s p=0.014 n=6
Total Time 14.43s (± 0.25%) 14.48s (± 0.22%) +0.05s (+ 0.35%) 14.43s 14.52s p=0.037 n=6
TFS - node (v18.15.0, x64)
Memory used 302,784k (± 0.01%) 302,754k (± 0.01%) ~ 302,712k 302,809k p=0.128 n=6
Parse Time 2.00s (± 1.17%) 2.00s (± 0.86%) ~ 1.98s 2.03s p=0.459 n=6
Bind Time 1.01s (± 1.31%) 1.00s (± 1.04%) ~ 0.99s 1.02s p=0.451 n=6
Check Time 6.33s (± 0.28%) 6.34s (± 0.49%) ~ 6.29s 6.38s p=0.803 n=6
Emit Time 3.61s (± 0.34%) 3.61s (± 0.41%) ~ 3.59s 3.63s p=0.934 n=6
Total Time 12.96s (± 0.30%) 12.95s (± 0.16%) ~ 12.93s 12.99s p=0.295 n=6
material-ui - node (v18.15.0, x64)
Memory used 511,211k (± 0.00%) 511,251k (± 0.01%) ~ 511,186k 511,373k p=0.078 n=6
Parse Time 2.65s (± 0.81%) 2.66s (± 0.51%) ~ 2.64s 2.67s p=0.365 n=6
Bind Time 0.99s (± 0.99%) 0.99s (± 1.23%) ~ 0.97s 1.00s p=0.865 n=6
Check Time 17.24s (± 0.23%) 17.31s (± 0.50%) ~ 17.19s 17.43s p=0.146 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.88s (± 0.22%) 20.95s (± 0.41%) ~ 20.84s 21.08s p=0.128 n=6
mui-docs - node (v18.15.0, x64)
Memory used 2,296,341k (± 0.00%) 2,296,522k (± 0.00%) +181k (+ 0.01%) 2,296,497k 2,296,573k p=0.005 n=6
Parse Time 11.98s (± 0.81%) 11.97s (± 0.75%) ~ 11.87s 12.13s p=1.000 n=6
Bind Time 2.66s (± 0.69%) 2.64s (± 0.31%) ~ 2.63s 2.65s p=0.121 n=6
Check Time 101.41s (± 0.87%) 101.53s (± 0.66%) ~ 100.73s 102.62s p=1.000 n=6
Emit Time 0.32s (± 1.60%) 0.32s (± 1.97%) ~ 0.31s 0.33s p=0.386 n=6
Total Time 116.37s (± 0.81%) 116.47s (± 0.57%) ~ 115.64s 117.55s p=1.000 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,394,444k (± 0.01%) 2,396,586k (± 0.03%) +2,142k (+ 0.09%) 2,395,763k 2,397,458k p=0.005 n=6
Parse Time 5.04s (± 1.25%) 5.05s (± 1.49%) ~ 4.94s 5.14s p=0.748 n=6
Bind Time 1.89s (± 0.43%) 1.90s (± 0.86%) ~ 1.87s 1.92s p=0.605 n=6
Check Time 33.61s (± 0.31%) 33.68s (± 0.22%) ~ 33.59s 33.81s p=0.173 n=6
Emit Time 2.64s (± 0.99%) 2.66s (± 1.49%) ~ 2.59s 2.70s p=0.295 n=6
Total Time 43.19s (± 0.27%) 43.30s (± 0.33%) ~ 43.17s 43.52s p=0.689 n=6
self-compiler - node (v18.15.0, x64)
Memory used 414,431k (± 0.01%) 415,047k (± 0.01%) +616k (+ 0.15%) 415,001k 415,088k p=0.005 n=6
Parse Time 2.82s (± 0.70%) 2.79s (± 0.84%) ~ 2.76s 2.82s p=0.087 n=6
Bind Time 1.07s (± 0.48%) 1.07s (± 0.51%) ~ 1.06s 1.07s p=0.640 n=6
Check Time 15.14s (± 0.40%) 15.26s (± 0.29%) +0.12s (+ 0.78%) 15.19s 15.32s p=0.008 n=6
Emit Time 1.10s (± 1.33%) 1.11s (± 1.47%) ~ 1.08s 1.12s p=0.564 n=6
Total Time 20.13s (± 0.40%) 20.22s (± 0.33%) ~ 20.13s 20.32s p=0.093 n=6
vscode - node (v18.15.0, x64)
Memory used 2,859,177k (± 0.01%) 2,859,763k (± 0.00%) +586k (+ 0.02%) 2,859,683k 2,859,806k p=0.005 n=6
Parse Time 10.76s (± 0.11%) 10.76s (± 0.35%) ~ 10.71s 10.81s p=1.000 n=6
Bind Time 3.44s (± 0.12%) 3.44s (± 0.34%) ~ 3.43s 3.46s p=0.584 n=6
Check Time 61.28s (± 0.29%) 61.16s (± 0.55%) ~ 60.69s 61.49s p=0.688 n=6
Emit Time 17.41s (±10.15%) 16.33s (± 0.40%) ~ 16.25s 16.44s p=0.810 n=6
Total Time 92.89s (± 1.89%) 91.68s (± 0.36%) ~ 91.26s 92.05s p=0.173 n=6
webpack - node (v18.15.0, x64)
Memory used 397,024k (± 0.01%) 397,141k (± 0.02%) +117k (+ 0.03%) 397,049k 397,211k p=0.013 n=6
Parse Time 3.13s (± 0.94%) 3.14s (± 0.77%) ~ 3.10s 3.17s p=0.373 n=6
Bind Time 1.38s (± 1.63%) 1.39s (± 1.55%) ~ 1.37s 1.43s p=0.105 n=6
Check Time 13.93s (± 0.31%) 14.06s (± 0.40%) +0.13s (+ 0.95%) 13.97s 14.13s p=0.008 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 18.44s (± 0.18%) 18.60s (± 0.22%) +0.16s (+ 0.87%) 18.54s 18.64s p=0.005 n=6
xstate - node (v18.15.0, x64)
Memory used 513,132k (± 0.01%) 513,198k (± 0.02%) ~ 513,106k 513,414k p=0.298 n=6
Parse Time 3.28s (± 0.36%) 3.27s (± 0.37%) ~ 3.26s 3.29s p=0.507 n=6
Bind Time 1.54s (± 0.49%) 1.54s (± 0.49%) ~ 1.53s 1.55s p=0.487 n=6
Check Time 2.86s (± 0.41%) 2.87s (± 0.90%) ~ 2.83s 2.90s p=0.618 n=6
Emit Time 0.08s (± 0.00%) 0.07s (± 0.00%) 🟩-0.01s (-12.50%) 0.07s 0.07s p=0.001 n=6
Total Time 7.76s (± 0.28%) 7.77s (± 0.35%) ~ 7.73s 7.81s p=0.688 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,354ms (± 0.85%) 2,365ms (± 0.58%) ~ 2,354ms 2,391ms p=0.230 n=6
Req 2 - geterr 5,580ms (± 1.00%) 5,585ms (± 0.36%) ~ 5,564ms 5,620ms p=0.936 n=6
Req 3 - references 328ms (± 1.27%) 330ms (± 0.97%) ~ 324ms 333ms p=0.624 n=6
Req 4 - navto 274ms (± 0.79%) 274ms (± 0.00%) ~ 274ms 274ms p=1.000 n=6
Req 5 - completionInfo count 1,357 (± 0.00%) 1,357 (± 0.00%) ~ 1,357 1,357 p=1.000 n=6
Req 5 - completionInfo 86ms (± 7.52%) 79ms (± 0.65%) ~ 79ms 80ms p=0.103 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,522ms (± 0.42%) 2,514ms (± 0.53%) ~ 2,493ms 2,532ms p=0.228 n=6
Req 2 - geterr 4,195ms (± 1.94%) 4,177ms (± 0.52%) ~ 4,152ms 4,214ms p=1.000 n=6
Req 3 - references 344ms (± 6.92%) 333ms (± 0.23%) ~ 332ms 334ms p=0.565 n=6
Req 4 - navto 284ms (± 1.03%) 285ms (± 0.29%) ~ 285ms 287ms p=1.000 n=6
Req 5 - completionInfo count 1,519 (± 0.00%) 1,519 (± 0.00%) ~ 1,519 1,519 p=1.000 n=6
Req 5 - completionInfo 81ms (± 8.93%) 76ms (± 5.92%) ~ 74ms 85ms p=0.157 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,608ms (± 0.24%) 2,597ms (± 0.67%) ~ 2,567ms 2,620ms p=0.170 n=6
Req 2 - geterr 1,750ms (± 2.03%) 1,741ms (± 2.90%) ~ 1,659ms 1,786ms p=0.873 n=6
Req 3 - references 123ms (± 6.76%) 118ms (± 9.54%) ~ 105ms 128ms p=0.872 n=6
Req 4 - navto 373ms (± 3.08%) 369ms (± 1.30%) ~ 360ms 373ms p=0.936 n=6
Req 5 - completionInfo count 2,079 (± 0.00%) 2,079 (± 0.00%) ~ 2,079 2,079 p=1.000 n=6
Req 5 - completionInfo 305ms (± 1.08%) 307ms (± 1.61%) ~ 301ms 313ms p=0.810 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstateTSServer - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v18.15.0, x64)
Execution time 153.07ms (± 0.18%) 153.08ms (± 0.17%) ~ 152.14ms 155.04ms p=0.618 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 229.04ms (± 0.17%) 228.70ms (± 0.17%) -0.34ms (- 0.15%) 227.37ms 231.75ms p=0.000 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 221.72ms (± 0.17%) 221.75ms (± 0.16%) ~ 219.92ms 227.86ms p=0.159 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 221.79ms (± 0.16%) 221.78ms (± 0.15%) ~ 220.19ms 226.38ms p=0.991 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@danvk
Copy link
Contributor Author

danvk commented Mar 6, 2024

I'm surprised this wasn't a win. Might be time to stop optimizing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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