Skip to content

Conversation

JoostK
Copy link
Contributor

@JoostK JoostK commented Jul 12, 2022

Fixes #49845

This change threads the computed type of conditional expressions into checkTestingKnownTruthyCallableOrAwaitableType to avoid recursively revisiting expression subtrees, resulting in an exponential performance drop. The changed code is similar to how it was before #42835.

The test case used to run in ~13s on my laptop before the fix, and now completes instantly again (check time reported as 0.00s)

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jul 12, 2022
@@ -38232,7 +38233,7 @@ namespace ts {
? condExpr.right
: condExpr;
if (isModuleExportsAccessExpression(location)) return;
const type = checkTruthinessExpression(location);
const type = location === condExpr ? condType : checkTruthinessExpression(location);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If anyone has ideas on how to avoid this checkTruthinessExpression altogether, please let me know.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that seems tricky because it looks like location is either condExpr, and we already have the type, or it is condExpr.right, and then... we haven't visited yet in the trampoline on onOperator, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, this is my understanding as well. And I don't think that a dynamic programming like approach is worth it here, given the overhead of caching the type of subtrees. Given that the performance issue that manifested itself is mitigated by the current changes I'd consider it fine that we leave this like this, at least until another performance bottleneck is observed.

@DanielRosenwasser
Copy link
Member

@typescript-bot pack this
@typescript-bot test this
@typescript-bot user test this inline
@typescript-bot run dt
@typescript-bot perf test this

1 similar comment
@DanielRosenwasser
Copy link
Member

@typescript-bot pack this
@typescript-bot test this
@typescript-bot user test this inline
@typescript-bot run dt
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 15, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 15, 2022

Heya @DanielRosenwasser, I've started to run the diff-based user code test suite on this PR at a594c6a. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 15, 2022

Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at a594c6a. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 15, 2022

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 15, 2022

Heya @DanielRosenwasser, I've started to run the parallelized Definitely Typed test suite on this PR at a594c6a. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

@DanielRosenwasser
The results of the user tests run you requested are in!

Here they are:

Comparison Report - main..refs/pull/49881/merge

[uglify-js]

1 of 1 projects failed to build with the old tsc

/mnt/ts_downloads/uglify-js/tsconfig.json

  • error TS2322: Type 'boolean' is not assignable to type 'never'.
    • /mnt/ts_downloads/uglify-js/node_modules/uglify-js/lib/compress.js(2343,25)

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 16, 2022

Hey @DanielRosenwasser, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/129830/artifacts?artifactName=tgz&fileId=C14027BCD436216EF809460CA9E42F089DC3B7ABC32BB7A29F505236DCABEDE302&fileName=/typescript-4.8.0-insiders.20220715.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - main..49881
Metric main 49881 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 360,131k (± 0.02%) 360,094k (± 0.02%) -37k (- 0.01%) 359,936k 360,240k
Parse Time 2.09s (± 0.40%) 2.09s (± 0.43%) -0.00s (- 0.19%) 2.07s 2.11s
Bind Time 0.89s (± 1.34%) 0.89s (± 0.91%) +0.00s (+ 0.23%) 0.87s 0.90s
Check Time 5.98s (± 0.46%) 5.98s (± 0.42%) +0.00s (+ 0.02%) 5.93s 6.03s
Emit Time 6.10s (± 0.52%) 6.10s (± 0.61%) -0.00s (- 0.03%) 6.04s 6.21s
Total Time 15.07s (± 0.33%) 15.06s (± 0.28%) -0.00s (- 0.02%) 14.98s 15.15s
Compiler-Unions - node (v10.16.3, x64)
Memory used 206,629k (± 0.04%) 206,647k (± 0.03%) +19k (+ 0.01%) 206,543k 206,758k
Parse Time 0.83s (± 0.84%) 0.83s (± 0.70%) +0.00s (+ 0.24%) 0.82s 0.85s
Bind Time 0.53s (± 1.57%) 0.53s (± 1.29%) 0.00s ( 0.00%) 0.51s 0.54s
Check Time 7.11s (± 0.31%) 7.09s (± 0.61%) -0.02s (- 0.30%) 7.02s 7.18s
Emit Time 2.52s (± 0.90%) 2.49s (± 0.65%) -0.03s (- 1.31%) 2.44s 2.52s
Total Time 10.98s (± 0.36%) 10.93s (± 0.47%) -0.05s (- 0.47%) 10.85s 11.04s
Monaco - node (v10.16.3, x64)
Memory used 344,037k (± 0.01%) 343,987k (± 0.01%) -50k (- 0.01%) 343,854k 344,066k
Parse Time 1.59s (± 0.52%) 1.59s (± 0.38%) 0.00s ( 0.00%) 1.58s 1.61s
Bind Time 0.75s (± 0.86%) 0.75s (± 0.89%) +0.00s (+ 0.13%) 0.75s 0.78s
Check Time 5.97s (± 0.45%) 5.96s (± 0.57%) -0.01s (- 0.13%) 5.90s 6.04s
Emit Time 3.25s (± 0.70%) 3.24s (± 0.89%) -0.02s (- 0.49%) 3.19s 3.33s
Total Time 11.57s (± 0.32%) 11.55s (± 0.41%) -0.02s (- 0.20%) 11.44s 11.62s
TFS - node (v10.16.3, x64)
Memory used 305,165k (± 0.01%) 305,151k (± 0.02%) -14k (- 0.00%) 304,992k 305,296k
Parse Time 1.28s (± 0.58%) 1.28s (± 0.58%) +0.00s (+ 0.23%) 1.27s 1.30s
Bind Time 0.71s (± 0.63%) 0.71s (± 0.78%) 0.00s ( 0.00%) 0.70s 0.73s
Check Time 5.39s (± 0.58%) 5.42s (± 0.50%) +0.02s (+ 0.43%) 5.37s 5.51s
Emit Time 3.40s (± 0.75%) 3.40s (± 1.06%) +0.00s (+ 0.12%) 3.34s 3.48s
Total Time 10.79s (± 0.46%) 10.81s (± 0.60%) +0.03s (+ 0.25%) 10.69s 11.01s
material-ui - node (v10.16.3, x64)
Memory used 469,395k (± 0.01%) 469,425k (± 0.01%) +30k (+ 0.01%) 469,240k 469,510k
Parse Time 1.82s (± 0.42%) 1.83s (± 0.50%) +0.00s (+ 0.22%) 1.81s 1.85s
Bind Time 0.68s (± 1.58%) 0.68s (± 1.54%) +0.00s (+ 0.59%) 0.66s 0.70s
Check Time 14.47s (± 0.41%) 14.48s (± 0.41%) +0.01s (+ 0.07%) 14.39s 14.65s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.98s (± 0.40%) 16.99s (± 0.37%) +0.02s (+ 0.12%) 16.89s 17.17s
xstate - node (v10.16.3, x64)
Memory used 581,365k (± 1.25%) 581,230k (± 1.26%) -135k (- 0.02%) 577,622k 610,697k
Parse Time 2.60s (± 0.27%) 2.60s (± 0.36%) -0.00s (- 0.08%) 2.58s 2.62s
Bind Time 1.02s (± 0.58%) 1.02s (± 0.93%) 0.00s ( 0.00%) 1.00s 1.04s
Check Time 1.56s (± 0.53%) 1.55s (± 0.49%) -0.01s (- 0.71%) 1.53s 1.56s
Emit Time 0.07s (± 0.00%) 0.07s (± 0.00%) 0.00s ( 0.00%) 0.07s 0.07s
Total Time 5.24s (± 0.25%) 5.24s (± 0.39%) -0.01s (- 0.13%) 5.19s 5.28s
Angular - node (v12.1.0, x64)
Memory used 337,641k (± 0.02%) 337,712k (± 0.02%) +72k (+ 0.02%) 337,587k 337,859k
Parse Time 2.08s (± 0.59%) 2.09s (± 0.79%) +0.01s (+ 0.38%) 2.06s 2.12s
Bind Time 0.86s (± 1.40%) 0.86s (± 0.72%) +0.00s (+ 0.23%) 0.84s 0.87s
Check Time 5.84s (± 0.41%) 5.83s (± 0.53%) -0.01s (- 0.15%) 5.78s 5.91s
Emit Time 6.39s (± 0.56%) 6.41s (± 1.05%) +0.02s (+ 0.34%) 6.31s 6.61s
Total Time 15.17s (± 0.42%) 15.19s (± 0.63%) +0.02s (+ 0.13%) 15.00s 15.46s
Compiler-Unions - node (v12.1.0, x64)
Memory used 194,265k (± 0.03%) 194,206k (± 0.13%) -59k (- 0.03%) 193,170k 194,374k
Parse Time 0.83s (± 0.58%) 0.83s (± 1.04%) +0.01s (+ 0.60%) 0.82s 0.86s
Bind Time 0.55s (± 1.33%) 0.55s (± 1.10%) -0.00s (- 0.55%) 0.54s 0.56s
Check Time 6.68s (± 0.48%) 6.71s (± 0.74%) +0.03s (+ 0.45%) 6.62s 6.83s
Emit Time 2.57s (± 2.07%) 2.53s (± 1.05%) -0.04s (- 1.44%) 2.47s 2.57s
Total Time 10.62s (± 0.65%) 10.61s (± 0.66%) -0.00s (- 0.02%) 10.48s 10.76s
Monaco - node (v12.1.0, x64)
Memory used 326,958k (± 0.03%) 326,983k (± 0.03%) +25k (+ 0.01%) 326,723k 327,270k
Parse Time 1.59s (± 0.52%) 1.57s (± 0.90%) -0.02s (- 1.01%) 1.53s 1.61s
Bind Time 0.74s (± 0.70%) 0.74s (± 0.78%) -0.00s (- 0.13%) 0.73s 0.75s
Check Time 5.79s (± 0.30%) 5.79s (± 0.32%) -0.00s (- 0.03%) 5.76s 5.84s
Emit Time 3.28s (± 0.37%) 3.28s (± 0.55%) +0.00s (+ 0.03%) 3.25s 3.33s
Total Time 11.40s (± 0.19%) 11.39s (± 0.23%) -0.01s (- 0.12%) 11.32s 11.44s
TFS - node (v12.1.0, x64)
Memory used 289,731k (± 0.02%) 289,646k (± 0.07%) -84k (- 0.03%) 288,866k 289,810k
Parse Time 1.30s (± 0.78%) 1.29s (± 0.54%) -0.01s (- 0.39%) 1.27s 1.30s
Bind Time 0.71s (± 0.96%) 0.72s (± 0.86%) +0.00s (+ 0.56%) 0.71s 0.73s
Check Time 5.33s (± 0.34%) 5.34s (± 0.46%) +0.01s (+ 0.23%) 5.30s 5.41s
Emit Time 3.51s (± 0.88%) 3.52s (± 0.92%) +0.00s (+ 0.11%) 3.45s 3.60s
Total Time 10.85s (± 0.30%) 10.87s (± 0.54%) +0.02s (+ 0.16%) 10.76s 11.04s
material-ui - node (v12.1.0, x64)
Memory used 448,497k (± 0.02%) 448,502k (± 0.02%) +6k (+ 0.00%) 448,337k 448,681k
Parse Time 1.82s (± 0.56%) 1.82s (± 0.58%) +0.00s (+ 0.22%) 1.81s 1.86s
Bind Time 0.67s (± 0.70%) 0.67s (± 0.60%) -0.00s (- 0.15%) 0.66s 0.68s
Check Time 12.99s (± 0.34%) 13.01s (± 0.87%) +0.02s (+ 0.18%) 12.84s 13.40s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.48s (± 0.31%) 15.51s (± 0.74%) +0.03s (+ 0.16%) 15.32s 15.90s
xstate - node (v12.1.0, x64)
Memory used 546,741k (± 1.32%) 543,370k (± 0.02%) -3,371k (- 0.62%) 543,242k 543,688k
Parse Time 2.56s (± 0.57%) 2.54s (± 0.45%) -0.02s (- 0.82%) 2.52s 2.56s
Bind Time 1.03s (± 1.11%) 1.03s (± 0.94%) -0.00s (- 0.10%) 1.01s 1.05s
Check Time 1.50s (± 0.71%) 1.48s (± 0.59%) -0.01s (- 0.87%) 1.46s 1.50s
Emit Time 0.07s (± 0.00%) 0.07s (± 4.13%) +0.00s (+ 2.86%) 0.07s 0.08s
Total Time 5.16s (± 0.42%) 5.13s (± 0.30%) -0.03s (- 0.58%) 5.11s 5.18s
Angular - node (v14.15.1, x64)
Memory used 335,941k (± 0.01%) 335,929k (± 0.01%) -13k (- 0.00%) 335,856k 336,016k
Parse Time 2.06s (± 0.50%) 2.06s (± 0.56%) +0.00s (+ 0.05%) 2.04s 2.09s
Bind Time 0.90s (± 0.66%) 0.89s (± 0.55%) -0.00s (- 0.22%) 0.89s 0.91s
Check Time 5.81s (± 0.52%) 5.80s (± 0.54%) -0.01s (- 0.21%) 5.72s 5.87s
Emit Time 6.38s (± 0.45%) 6.35s (± 0.58%) -0.03s (- 0.42%) 6.30s 6.46s
Total Time 15.14s (± 0.36%) 15.10s (± 0.28%) -0.04s (- 0.26%) 15.00s 15.20s
Compiler-Unions - node (v14.15.1, x64)
Memory used 192,871k (± 0.01%) 192,872k (± 0.01%) +1k (+ 0.00%) 192,834k 192,926k
Parse Time 0.85s (± 0.82%) 0.85s (± 0.53%) -0.00s (- 0.35%) 0.84s 0.86s
Bind Time 0.57s (± 0.88%) 0.57s (± 0.78%) +0.00s (+ 0.53%) 0.56s 0.58s
Check Time 6.70s (± 0.40%) 6.71s (± 0.51%) +0.01s (+ 0.12%) 6.60s 6.77s
Emit Time 2.48s (± 0.84%) 2.48s (± 0.74%) +0.00s (+ 0.08%) 2.42s 2.51s
Total Time 10.60s (± 0.38%) 10.60s (± 0.45%) +0.01s (+ 0.07%) 10.44s 10.68s
Monaco - node (v14.15.1, x64)
Memory used 325,743k (± 0.00%) 325,718k (± 0.01%) -25k (- 0.01%) 325,670k 325,767k
Parse Time 1.58s (± 0.57%) 1.58s (± 0.43%) 0.00s ( 0.00%) 1.56s 1.59s
Bind Time 0.78s (± 0.57%) 0.78s (± 0.57%) +0.00s (+ 0.00%) 0.77s 0.79s
Check Time 5.66s (± 0.32%) 5.68s (± 0.52%) +0.02s (+ 0.39%) 5.62s 5.77s
Emit Time 3.35s (± 0.70%) 3.40s (± 1.11%) +0.04s (+ 1.25%) 3.34s 3.53s
Total Time 11.37s (± 0.31%) 11.44s (± 0.58%) +0.07s (+ 0.58%) 11.30s 11.65s
TFS - node (v14.15.1, x64)
Memory used 288,814k (± 0.01%) 288,820k (± 0.01%) +6k (+ 0.00%) 288,783k 288,850k
Parse Time 1.33s (± 1.84%) 1.32s (± 1.48%) -0.00s (- 0.38%) 1.29s 1.36s
Bind Time 0.77s (± 4.15%) 0.75s (± 1.85%) -0.02s (- 2.34%) 0.73s 0.80s
Check Time 5.33s (± 0.49%) 5.34s (± 0.65%) +0.01s (+ 0.21%) 5.31s 5.46s
Emit Time 3.58s (± 2.16%) 3.57s (± 2.09%) -0.01s (- 0.17%) 3.44s 3.73s
Total Time 11.01s (± 0.80%) 10.99s (± 0.82%) -0.02s (- 0.18%) 10.85s 11.25s
material-ui - node (v14.15.1, x64)
Memory used 446,662k (± 0.01%) 446,344k (± 0.08%) -318k (- 0.07%) 445,257k 446,623k
Parse Time 1.88s (± 0.25%) 1.88s (± 0.32%) -0.00s (- 0.11%) 1.86s 1.89s
Bind Time 0.72s (± 1.32%) 0.73s (± 1.23%) +0.00s (+ 0.14%) 0.72s 0.76s
Check Time 13.17s (± 0.76%) 13.12s (± 0.58%) -0.05s (- 0.36%) 12.93s 13.30s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.77s (± 0.68%) 15.72s (± 0.49%) -0.05s (- 0.33%) 15.52s 15.89s
xstate - node (v14.15.1, x64)
Memory used 541,310k (± 0.00%) 541,248k (± 0.00%) -62k (- 0.01%) 541,210k 541,288k
Parse Time 2.60s (± 0.34%) 2.60s (± 0.45%) +0.01s (+ 0.27%) 2.58s 2.63s
Bind Time 1.15s (± 1.26%) 1.15s (± 0.78%) -0.01s (- 0.69%) 1.13s 1.16s
Check Time 1.54s (± 0.24%) 1.53s (± 0.48%) -0.02s (- 1.04%) 1.51s 1.54s
Emit Time 0.07s (± 4.13%) 0.07s (± 4.13%) 0.00s ( 0.00%) 0.07s 0.08s
Total Time 5.37s (± 0.43%) 5.35s (± 0.36%) -0.02s (- 0.28%) 5.33s 5.41s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 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)
  • xstate - node (v10.16.3, x64)
  • xstate - node (v12.1.0, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 49881 10
Baseline main 10

TSServer

Comparison Report - main..49881
Metric main 49881 Delta Best Worst
xstateTSServer - node (v10.16.3, x64)
Initial load time 2,157.70ms (± 0.38%) 2,155.90ms (± 0.22%) -1.80ms (- 0.08%) 2,145.00ms 2,164.00ms
Geterr time 761.80ms (± 0.39%) 754.90ms (± 0.36%) -6.90ms (- 0.91%) 747.00ms 761.00ms
References time 96.10ms (± 1.36%) 94.40ms (± 1.54%) -1.70ms (- 1.77%) 92.00ms 99.00ms
Navto time 252.50ms (± 0.78%) 251.40ms (± 0.55%) -1.10ms (- 0.44%) 249.00ms 255.00ms
Navto count 256.00 (± 0.00%) 256.00 (± 0.00%) 0.00 ( 0.00%) 256.00 256.00
Completions time 244.90ms (± 1.61%) 245.00ms (± 1.43%) +0.10ms (+ 0.04%) 235.00ms 251.00ms
Completions count 3,205.00 (± 0.00%) 3,205.00 (± 0.00%) 0.00 ( 0.00%) 3,205.00 3,205.00
xstateTSServer - node (v12.1.0, x64)
Initial load time 2,099.50ms (± 0.55%) 2,086.40ms (± 0.48%) -13.10ms (- 0.62%) 2,067.00ms 2,111.00ms
Geterr time 747.90ms (± 0.43%) 737.10ms (± 0.40%) -10.80ms (- 1.44%) 730.00ms 745.00ms
References time 67.60ms (± 0.88%) 66.40ms (± 2.79%) -1.20ms (- 1.78%) 64.00ms 73.00ms
Navto time 239.90ms (± 1.54%) 240.00ms (± 1.40%) +0.10ms (+ 0.04%) 229.00ms 244.00ms
Navto count 256.00 (± 0.00%) 256.00 (± 0.00%) 0.00 ( 0.00%) 256.00 256.00
Completions time 239.30ms (± 0.74%) 241.60ms (± 1.09%) +2.30ms (+ 0.96%) 235.00ms 248.00ms
Completions count 3,205.00 (± 0.00%) 3,205.00 (± 0.00%) 0.00 ( 0.00%) 3,205.00 3,205.00
xstateTSServer - node (v14.15.1, x64)
Initial load time 2,213.80ms (± 0.38%) 2,224.70ms (± 0.49%) +10.90ms (+ 0.49%) 2,205.00ms 2,246.00ms
Geterr time 771.70ms (± 0.33%) 758.80ms (± 0.34%) -12.90ms (- 1.67%) 753.00ms 763.00ms
References time 64.90ms (± 1.08%) 67.30ms (± 1.11%) +2.40ms (+ 3.70%) 65.00ms 69.00ms
Navto time 251.60ms (± 0.35%) 247.30ms (± 0.75%) -4.30ms (- 1.71%) 243.00ms 251.00ms
Navto count 256.00 (± 0.00%) 256.00 (± 0.00%) 0.00 ( 0.00%) 256.00 256.00
Completions time 241.20ms (± 0.49%) 241.50ms (± 0.42%) +0.30ms (+ 0.12%) 239.00ms 244.00ms
Completions count 3,205.00 (± 0.00%) 3,205.00 (± 0.00%) 0.00 ( 0.00%) 3,205.00 3,205.00
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 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
  • xstateTSServer - node (v10.16.3, x64)
  • xstateTSServer - node (v12.1.0, x64)
  • xstateTSServer - node (v14.15.1, x64)
Benchmark Name Iterations
Current 49881 10
Baseline main 10

Developer Information:

Download Benchmark

@JoostK
Copy link
Contributor Author

JoostK commented Jul 18, 2022

Just a heads up: I'll be on vacation for the next couple of weeks so won't be able to update this PR in the meantime. Feel free to push additional changes if needed, open another PR, or just wait until I'm back.

Copy link
Member

@gabritto gabritto left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for this contribution!
Let's wait for the experts.

@@ -0,0 +1,5 @@
// @strictNullChecks: true
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we have a better way of capturing this kind of test, where the thing we're interested in is the execution time.

Copy link
Member

Choose a reason for hiding this comment

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

Historically we don't - but tests do have a timeout (around 50s), so if you make sure they're large enough to hit the timeout before your change, they're a decent test; they won't capture tiny pretty regressions, but will prevent big ones. We have other tests in this vein.

Copy link
Member

Choose a reason for hiding this comment

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

Ok then. @JoostK can you make this example much much bigger, so that the test would timeout without the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add 4 additional binary ops, which would have brought check times up by a factor of 16 (easily pushing it beyond the 50s threshold)

if (!strictNullChecks) return;
if (!(getTypeFacts(condType) & TypeFacts.Truthy)) return;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this check only be done if location is ultimately condExpr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you are correct; as this check is indeed also done within helper based on the resolved type. Removing this.

@imirkin
Copy link

imirkin commented Aug 23, 2022

@JoostK apologies if you're still on vacation, but any plans on updating this change? If not I guess I could try, but I'm not at all familiar with TS internals...

@JoostK JoostK force-pushed the perf/recursive-function-checks branch from a594c6a to dd5a78b Compare August 26, 2022 21:09
@JoostK
Copy link
Contributor Author

JoostK commented Aug 26, 2022

I have incorporated the feedback in the latest update, PTAL.

@gabritto gabritto requested a review from weswigham August 26, 2022 22:23
@weswigham weswigham merged commit 71b2ba6 into microsoft:main Aug 27, 2022
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
Archived in project
Development

Successfully merging this pull request may close these issues.

TypeScript 4.7.4: Exponential behavior in strict type checking
6 participants