Skip to content

Fix bugs in module specifier generation with paths/typesVersions#49792

Merged
andrewbranch merged 6 commits intomicrosoft:mainfrom
andrewbranch:bug/49290
Aug 3, 2022
Merged

Fix bugs in module specifier generation with paths/typesVersions#49792
andrewbranch merged 6 commits intomicrosoft:mainfrom
andrewbranch:bug/49290

Conversation

@andrewbranch
Copy link
Copy Markdown
Member

@andrewbranch andrewbranch commented Jul 5, 2022

This was much more difficult to do correctly than I expected, but it fixes more than what I set out to fix.

Fixes #49034
Fixes #49290

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Jul 5, 2022
@andrewbranch
Copy link
Copy Markdown
Member Author

@typescript-bot perf test this

@typescript-bot
Copy link
Copy Markdown
Collaborator

typescript-bot commented Jul 5, 2022

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

Update: The results are in!

Comment thread src/compiler/moduleSpecifiers.ts Fixed
@typescript-bot
Copy link
Copy Markdown
Collaborator

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

Here they are:

Compiler

Comparison Report - main..49792
Metric main 49792 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 359,706k (± 0.02%) 359,714k (± 0.02%) +8k (+ 0.00%) 359,581k 359,927k
Parse Time 2.08s (± 0.19%) 2.09s (± 0.28%) +0.01s (+ 0.43%) 2.08s 2.10s
Bind Time 0.90s (± 0.85%) 0.90s (± 0.94%) +0.00s (+ 0.45%) 0.88s 0.92s
Check Time 5.99s (± 0.40%) 5.99s (± 0.65%) +0.00s (+ 0.02%) 5.89s 6.06s
Emit Time 6.13s (± 0.93%) 6.12s (± 0.56%) -0.00s (- 0.03%) 6.06s 6.22s
Total Time 15.09s (± 0.46%) 15.10s (± 0.36%) +0.01s (+ 0.09%) 15.02s 15.25s
Compiler-Unions - node (v10.16.3, x64)
Memory used 206,663k (± 0.03%) 206,671k (± 0.04%) +8k (+ 0.00%) 206,516k 206,817k
Parse Time 0.84s (± 0.41%) 0.83s (± 0.78%) -0.00s (- 0.60%) 0.81s 0.84s
Bind Time 0.53s (± 0.69%) 0.52s (± 1.80%) -0.00s (- 0.57%) 0.50s 0.55s
Check Time 7.14s (± 0.43%) 7.12s (± 0.29%) -0.02s (- 0.24%) 7.07s 7.18s
Emit Time 2.51s (± 0.40%) 2.51s (± 0.88%) +0.00s (+ 0.16%) 2.45s 2.54s
Total Time 11.02s (± 0.31%) 10.99s (± 0.32%) -0.02s (- 0.22%) 10.91s 11.06s
Monaco - node (v10.16.3, x64)
Memory used 343,891k (± 0.02%) 343,970k (± 0.01%) +79k (+ 0.02%) 343,875k 344,093k
Parse Time 1.59s (± 0.87%) 1.59s (± 0.67%) 0.00s ( 0.00%) 1.57s 1.62s
Bind Time 0.77s (± 0.58%) 0.77s (± 0.52%) -0.00s (- 0.39%) 0.76s 0.78s
Check Time 5.94s (± 0.49%) 5.95s (± 0.37%) +0.01s (+ 0.20%) 5.89s 5.99s
Emit Time 3.28s (± 0.83%) 3.26s (± 0.49%) -0.02s (- 0.58%) 3.23s 3.30s
Total Time 11.58s (± 0.56%) 11.57s (± 0.27%) -0.01s (- 0.09%) 11.51s 11.65s
TFS - node (v10.16.3, x64)
Memory used 305,136k (± 0.01%) 305,137k (± 0.01%) +1k (+ 0.00%) 305,056k 305,190k
Parse Time 1.27s (± 0.59%) 1.28s (± 0.48%) +0.01s (+ 0.39%) 1.26s 1.29s
Bind Time 0.72s (± 0.47%) 0.73s (± 0.80%) +0.00s (+ 0.55%) 0.71s 0.74s
Check Time 5.40s (± 0.55%) 5.42s (± 0.47%) +0.02s (+ 0.30%) 5.37s 5.48s
Emit Time 3.44s (± 1.26%) 3.42s (± 0.75%) -0.02s (- 0.47%) 3.38s 3.49s
Total Time 10.83s (± 0.61%) 10.85s (± 0.40%) +0.01s (+ 0.10%) 10.77s 10.95s
material-ui - node (v10.16.3, x64)
Memory used 469,387k (± 0.02%) 469,411k (± 0.02%) +24k (+ 0.01%) 469,157k 469,562k
Parse Time 1.82s (± 0.55%) 1.82s (± 0.43%) -0.00s (- 0.22%) 1.81s 1.84s
Bind Time 0.69s (± 1.56%) 0.70s (± 1.11%) +0.01s (+ 1.45%) 0.67s 0.71s
Check Time 14.48s (± 0.74%) 14.49s (± 0.61%) +0.02s (+ 0.12%) 14.34s 14.67s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.99s (± 0.65%) 17.01s (± 0.53%) +0.02s (+ 0.12%) 16.86s 17.22s
xstate - node (v10.16.3, x64)
Memory used 584,542k (± 1.67%) 584,532k (± 1.67%) -10k (- 0.00%) 577,809k 610,826k
Parse Time 2.60s (± 0.18%) 2.59s (± 0.35%) -0.01s (- 0.23%) 2.57s 2.61s
Bind Time 1.03s (± 0.84%) 1.03s (± 0.90%) 0.00s ( 0.00%) 1.01s 1.05s
Check Time 1.56s (± 0.75%) 1.55s (± 0.71%) -0.01s (- 0.38%) 1.52s 1.58s
Emit Time 0.07s (± 3.14%) 0.07s (± 3.14%) 0.00s ( 0.00%) 0.07s 0.08s
Total Time 5.24s (± 0.19%) 5.24s (± 0.36%) -0.00s (- 0.04%) 5.20s 5.28s
Angular - node (v12.1.0, x64)
Memory used 337,198k (± 0.02%) 337,219k (± 0.02%) +21k (+ 0.01%) 337,084k 337,372k
Parse Time 2.10s (± 0.58%) 2.10s (± 0.81%) -0.00s (- 0.19%) 2.06s 2.14s
Bind Time 0.86s (± 0.42%) 0.86s (± 0.57%) 0.00s ( 0.00%) 0.85s 0.87s
Check Time 5.80s (± 0.76%) 5.82s (± 0.93%) +0.02s (+ 0.31%) 5.76s 6.02s
Emit Time 6.37s (± 0.62%) 6.42s (± 0.60%) +0.05s (+ 0.82%) 6.34s 6.49s
Total Time 15.13s (± 0.42%) 15.20s (± 0.45%) +0.07s (+ 0.44%) 15.10s 15.42s
Compiler-Unions - node (v12.1.0, x64)
Memory used 194,214k (± 0.07%) 194,287k (± 0.04%) +72k (+ 0.04%) 194,162k 194,499k
Parse Time 0.83s (± 0.58%) 0.82s (± 0.60%) -0.00s (- 0.24%) 0.82s 0.84s
Bind Time 0.55s (± 1.28%) 0.55s (± 0.95%) 0.00s ( 0.00%) 0.54s 0.56s
Check Time 6.67s (± 0.66%) 6.65s (± 0.41%) -0.03s (- 0.37%) 6.61s 6.73s
Emit Time 2.55s (± 0.95%) 2.53s (± 1.21%) -0.02s (- 0.78%) 2.47s 2.61s
Total Time 10.60s (± 0.59%) 10.56s (± 0.39%) -0.04s (- 0.42%) 10.47s 10.65s
Monaco - node (v12.1.0, x64)
Memory used 326,910k (± 0.01%) 326,965k (± 0.02%) +55k (+ 0.02%) 326,835k 327,067k
Parse Time 1.57s (± 0.57%) 1.57s (± 0.74%) +0.01s (+ 0.51%) 1.55s 1.60s
Bind Time 0.76s (± 0.79%) 0.76s (± 0.65%) 0.00s ( 0.00%) 0.75s 0.77s
Check Time 5.77s (± 0.44%) 5.78s (± 0.52%) +0.01s (+ 0.21%) 5.71s 5.86s
Emit Time 3.30s (± 0.58%) 3.29s (± 0.68%) -0.01s (- 0.39%) 3.25s 3.34s
Total Time 11.39s (± 0.39%) 11.40s (± 0.46%) +0.01s (+ 0.09%) 11.29s 11.51s
TFS - node (v12.1.0, x64)
Memory used 289,728k (± 0.03%) 289,740k (± 0.01%) +12k (+ 0.00%) 289,677k 289,891k
Parse Time 1.31s (± 0.73%) 1.30s (± 0.96%) -0.01s (- 0.69%) 1.28s 1.34s
Bind Time 0.73s (± 0.68%) 0.73s (± 0.94%) 0.00s ( 0.00%) 0.71s 0.74s
Check Time 5.33s (± 0.44%) 5.33s (± 0.47%) +0.01s (+ 0.11%) 5.26s 5.38s
Emit Time 3.54s (± 0.89%) 3.51s (± 0.75%) -0.03s (- 0.90%) 3.46s 3.57s
Total Time 10.90s (± 0.39%) 10.86s (± 0.37%) -0.04s (- 0.33%) 10.74s 10.93s
material-ui - node (v12.1.0, x64)
Memory used 447,926k (± 0.10%) 448,476k (± 0.01%) +550k (+ 0.12%) 448,353k 448,557k
Parse Time 1.82s (± 0.49%) 1.83s (± 0.44%) +0.01s (+ 0.66%) 1.81s 1.85s
Bind Time 0.68s (± 0.76%) 0.68s (± 0.85%) -0.00s (- 0.15%) 0.67s 0.69s
Check Time 13.11s (± 0.94%) 13.00s (± 0.57%) -0.11s (- 0.84%) 12.87s 13.20s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.61s (± 0.84%) 15.51s (± 0.49%) -0.10s (- 0.65%) 15.38s 15.72s
xstate - node (v12.1.0, x64)
Memory used 546,574k (± 1.32%) 546,607k (± 1.33%) +33k (+ 0.01%) 543,252k 575,880k
Parse Time 2.54s (± 0.33%) 2.54s (± 0.33%) +0.00s (+ 0.00%) 2.52s 2.56s
Bind Time 1.03s (± 1.04%) 1.02s (± 0.83%) -0.01s (- 0.97%) 1.00s 1.04s
Check Time 1.49s (± 0.60%) 1.49s (± 0.55%) -0.00s (- 0.33%) 1.47s 1.51s
Emit Time 0.07s (± 3.14%) 0.07s (± 0.00%) -0.00s (- 1.41%) 0.07s 0.07s
Total Time 5.14s (± 0.32%) 5.12s (± 0.38%) -0.02s (- 0.33%) 5.08s 5.18s
Angular - node (v14.15.1, x64)
Memory used 335,315k (± 0.01%) 335,352k (± 0.01%) +38k (+ 0.01%) 335,237k 335,440k
Parse Time 2.06s (± 0.61%) 2.06s (± 0.40%) -0.00s (- 0.24%) 2.04s 2.07s
Bind Time 0.90s (± 0.75%) 0.90s (± 0.41%) -0.00s (- 0.11%) 0.89s 0.90s
Check Time 5.75s (± 0.52%) 5.77s (± 0.39%) +0.02s (+ 0.28%) 5.71s 5.82s
Emit Time 6.39s (± 0.59%) 6.41s (± 0.94%) +0.02s (+ 0.27%) 6.31s 6.55s
Total Time 15.10s (± 0.38%) 15.13s (± 0.45%) +0.03s (+ 0.21%) 15.01s 15.28s
Compiler-Unions - node (v14.15.1, x64)
Memory used 192,823k (± 0.02%) 192,839k (± 0.02%) +16k (+ 0.01%) 192,782k 192,886k
Parse Time 0.84s (± 0.58%) 0.85s (± 0.72%) +0.01s (+ 0.83%) 0.84s 0.87s
Bind Time 0.58s (± 1.18%) 0.57s (± 0.84%) -0.01s (- 1.56%) 0.56s 0.58s
Check Time 6.71s (± 0.47%) 6.74s (± 0.42%) +0.03s (+ 0.45%) 6.66s 6.79s
Emit Time 2.50s (± 0.46%) 2.50s (± 0.72%) +0.00s (+ 0.04%) 2.47s 2.55s
Total Time 10.63s (± 0.31%) 10.66s (± 0.34%) +0.03s (+ 0.25%) 10.58s 10.75s
Monaco - node (v14.15.1, x64)
Memory used 325,665k (± 0.00%) 325,689k (± 0.00%) +25k (+ 0.01%) 325,661k 325,716k
Parse Time 1.58s (± 0.46%) 1.58s (± 0.66%) +0.00s (+ 0.25%) 1.56s 1.61s
Bind Time 0.80s (± 0.84%) 0.80s (± 0.96%) -0.00s (- 0.25%) 0.78s 0.82s
Check Time 5.71s (± 0.53%) 5.69s (± 0.48%) -0.02s (- 0.39%) 5.64s 5.73s
Emit Time 3.38s (± 0.86%) 3.37s (± 0.86%) -0.01s (- 0.24%) 3.33s 3.44s
Total Time 11.47s (± 0.37%) 11.44s (± 0.44%) -0.02s (- 0.22%) 11.35s 11.53s
TFS - node (v14.15.1, x64)
Memory used 288,747k (± 0.01%) 288,764k (± 0.01%) +17k (+ 0.01%) 288,702k 288,818k
Parse Time 1.32s (± 1.21%) 1.34s (± 1.57%) +0.02s (+ 1.59%) 1.29s 1.39s
Bind Time 0.79s (± 4.78%) 0.76s (± 4.04%) 🟩-0.02s (- 3.17%) 0.73s 0.85s
Check Time 5.34s (± 0.43%) 5.32s (± 0.51%) -0.01s (- 0.26%) 5.26s 5.38s
Emit Time 3.56s (± 2.01%) 3.61s (± 2.10%) +0.06s (+ 1.60%) 3.43s 3.77s
Total Time 11.00s (± 0.57%) 11.04s (± 0.80%) +0.04s (+ 0.35%) 10.77s 11.19s
material-ui - node (v14.15.1, x64)
Memory used 446,681k (± 0.01%) 446,673k (± 0.00%) -8k (- 0.00%) 446,629k 446,709k
Parse Time 1.87s (± 0.33%) 1.87s (± 0.48%) -0.00s (- 0.16%) 1.85s 1.89s
Bind Time 0.73s (± 1.29%) 0.73s (± 0.76%) +0.00s (+ 0.27%) 0.72s 0.75s
Check Time 13.08s (± 0.37%) 13.14s (± 1.11%) +0.06s (+ 0.43%) 12.92s 13.63s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.68s (± 0.35%) 15.73s (± 0.90%) +0.06s (+ 0.37%) 15.54s 16.21s
xstate - node (v14.15.1, x64)
Memory used 541,182k (± 0.01%) 541,227k (± 0.00%) +45k (+ 0.01%) 541,182k 541,286k
Parse Time 2.60s (± 0.36%) 2.60s (± 0.60%) +0.00s (+ 0.12%) 2.58s 2.65s
Bind Time 1.15s (± 1.09%) 1.14s (± 0.83%) -0.00s (- 0.26%) 1.13s 1.17s
Check Time 1.54s (± 0.62%) 1.54s (± 0.52%) -0.00s (- 0.19%) 1.53s 1.56s
Emit Time 0.07s (± 4.66%) 0.07s (± 4.95%) +0.00s (+ 2.74%) 0.07s 0.08s
Total Time 5.37s (± 0.25%) 5.36s (± 0.37%) -0.00s (- 0.06%) 5.32s 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 49792 10
Baseline main 10

TSServer

Comparison Report - main..49792
Metric main 49792 Delta Best Worst
xstateTSServer - node (v10.16.3, x64)
Initial load time 2,154.70ms (± 0.44%) 2,160.80ms (± 0.38%) +6.10ms (+ 0.28%) 2,144.00ms 2,180.00ms
Geterr time 753.20ms (± 0.44%) 756.40ms (± 0.65%) +3.20ms (+ 0.42%) 745.00ms 767.00ms
References time 94.50ms (± 0.63%) 95.40ms (± 0.87%) +0.90ms (+ 0.95%) 94.00ms 98.00ms
Navto time 250.70ms (± 0.96%) 252.00ms (± 0.84%) +1.30ms (+ 0.52%) 246.00ms 256.00ms
Navto count 256.00 (± 0.00%) 256.00 (± 0.00%) 0.00 ( 0.00%) 256.00 256.00
Completions time 243.10ms (± 1.36%) 245.60ms (± 1.14%) +2.50ms (+ 1.03%) 238.00ms 252.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,084.70ms (± 0.41%) 2,099.50ms (± 0.53%) +14.80ms (+ 0.71%) 2,073.00ms 2,119.00ms
Geterr time 746.90ms (± 0.43%) 749.20ms (± 0.59%) +2.30ms (+ 0.31%) 739.00ms 757.00ms
References time 67.60ms (± 1.01%) 68.20ms (± 1.60%) +0.60ms (+ 0.89%) 67.00ms 72.00ms
Navto time 239.90ms (± 1.19%) 243.20ms (± 1.32%) +3.30ms (+ 1.38%) 235.00ms 249.00ms
Navto count 256.00 (± 0.00%) 256.00 (± 0.00%) 0.00 ( 0.00%) 256.00 256.00
Completions time 239.50ms (± 0.97%) 242.90ms (± 0.96%) +3.40ms (+ 1.42%) 237.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,230.00ms (± 0.47%) 2,236.50ms (± 0.39%) +6.50ms (+ 0.29%) 2,222.00ms 2,266.00ms
Geterr time 766.10ms (± 0.76%) 770.60ms (± 0.64%) +4.50ms (+ 0.59%) 763.00ms 780.00ms
References time 65.30ms (± 1.44%) 65.80ms (± 1.66%) +0.50ms (+ 0.77%) 64.00ms 68.00ms
Navto time 252.70ms (± 0.98%) 250.00ms (± 0.77%) -2.70ms (- 1.07%) 246.00ms 255.00ms
Navto count 256.00 (± 0.00%) 256.00 (± 0.00%) 0.00 ( 0.00%) 256.00 256.00
Completions time 243.60ms (± 0.83%) 245.10ms (± 0.82%) +1.50ms (+ 0.62%) 242.00ms 252.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 49792 10
Baseline main 10

Developer Information:

Download Benchmark

@andrewbranch andrewbranch marked this pull request as ready for review July 5, 2022 23:35
validateEnding({ ending, value })
) {
const matchedStar = value.substring(prefix.length, value.length - suffix.length);
return key.replace("*", matchedStar);

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding

This replaces only the first occurrence of "*".
@andrewbranch andrewbranch requested a review from weswigham July 5, 2022 23:58
Copy link
Copy Markdown
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

I think Wesley is out (and you mentioned this in Please Review); I'm not an expert but it seems good to me and I appreciate the essay explaining what the deal is.

// importNameCodeFix_typesVersions.ts for an example.)
const mainExportFile = toPath(mainFileRelative, packageRootPath, getCanonicalFileName);
if (removeFileExtension(mainExportFile) === removeFileExtension(getCanonicalFileName(moduleFileToTry))) {
// ^ An arbitrary removal of file extension for this comparison is almost certainly wrong
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this intended to be a TODO?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

More of a hint for a future developer investigating bugs in this area—a TODO only if prompted by a user report.


// Simplify the full file path to something that can be resolved by Node.

const preferences = getPreferences(host, userPreferences, options, importingSourceFile);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this used outside the if block, or is it so cheap that it just doesn't matter where it is?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I assume I had a reason to move it; maybe refactored away in later edits, but it is trivially cheap.

@andrewbranch
Copy link
Copy Markdown
Member Author

Thanks for the review! I forgot this was the one with the big table. Writing that out actually helped my clarify my mental model of module specifier generation a lot, which was a topic I thought I already understood well.

@andrewbranch andrewbranch merged commit c82c9a9 into microsoft:main Aug 3, 2022
@andrewbranch andrewbranch deleted the bug/49290 branch August 3, 2022 20:58
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Archived in project

5 participants