Skip to content

Ensure that we copy empty NodeArrays during transform - #48490

Merged
Jake Bailey (jakebailey) merged 2 commits into
microsoft:mainfrom
jakebailey:fix-48379
Mar 30, 2022
Merged

Ensure that we copy empty NodeArrays during transform#48490
Jake Bailey (jakebailey) merged 2 commits into
microsoft:mainfrom
jakebailey:fix-48379

Conversation

@jakebailey

@jakebaileyJake Bailey (jakebailey) commented Mar 30, 2022

Copy link
Copy Markdown
Member

Fixes#48379
Fixes#45744 (most likely)

In order to offer snippet completion for method overrides, we emit code. During emit, each node gets __pos and __end properties as a side effect, so that later those positions relative to the just-emitted text can be used.

To produce the code for the override, we convert signatures, which involves converting types to nodes. Unfortunately, the empty NodeArray inside of the type {} was getting cached then reused instead of cached then cloned. This led to every instance of {} in the transformed tree being the same object, which then caused emit to set position info more than once on the same node, which then caused debug assertions because earlier {}s would have the position info from the last{}, which isn't legal.

So, during transform, when we are explicitly doing that "deep copy or reuse", actually ensure that a copy happens for empty NodeArrays.

I feel like it would be better for visitNodes to do this, or createNodeArray to do it, or similar, but doing so breaks some cases where it appears as though callers of visitNodes assume that the array is returned unmodified if empty, breaking some 25 cases.

@jakebailey

Copy link
Copy Markdown
MemberAuthor

TypeScript Bot (@typescript-bot) perf test this inline

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 30, 2022

Copy link
Copy Markdown
Contributor

Heya Jake Bailey (@jakebailey), I've started to run the perf test suite on this PR at 944315e. You can monitor the build here.

Update: The results are in!

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey)
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..48490

Metricmain48490DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used356,635k (± 0.02%)356,664k (± 0.02%)+29k (+ 0.01%)356,453k356,764k
Parse Time2.05s (± 0.52%)2.05s (± 0.56%)-0.01s (- 0.29%)2.02s2.07s
Bind Time0.86s (± 0.93%)0.86s (± 0.72%)+0.00s (+ 0.35%)0.85s0.87s
Check Time5.81s (± 0.53%)5.81s (± 0.58%)-0.01s (- 0.12%)5.74s5.86s
Emit Time6.00s (± 0.57%)5.99s (± 0.63%)-0.02s (- 0.28%)5.92s6.09s
Total Time14.73s (± 0.36%)14.71s (± 0.36%)-0.02s (- 0.17%)14.59s14.81s
Compiler-Unions - node (v10.16.3, x64)
Memory used205,783k (± 0.03%)205,760k (± 0.03%)-23k (- 0.01%)205,595k205,874k
Parse Time0.85s (± 0.58%)0.85s (± 0.56%)+0.00s (+ 0.12%)0.84s0.86s
Bind Time0.51s (± 0.78%)0.52s (± 0.66%)+0.01s (+ 1.17%)0.51s0.52s
Check Time7.92s (± 0.49%)7.92s (± 0.44%)+0.00s (+ 0.01%)7.84s8.03s
Emit Time2.50s (± 1.06%)2.52s (± 0.72%)+0.02s (+ 0.80%)2.49s2.57s
Total Time11.78s (± 0.44%)11.81s (± 0.35%)+0.03s (+ 0.25%)11.70s11.92s
Monaco - node (v10.16.3, x64)
Memory used343,621k (± 0.02%)343,617k (± 0.02%)-4k (- 0.00%)343,441k343,724k
Parse Time1.57s (± 0.42%)1.57s (± 0.56%)+0.00s (+ 0.00%)1.54s1.58s
Bind Time0.75s (± 0.49%)0.75s (± 0.74%)-0.00s (- 0.40%)0.74s0.76s
Check Time5.75s (± 0.38%)5.75s (± 0.29%)+0.00s (+ 0.02%)5.71s5.78s
Emit Time3.24s (± 0.62%)3.23s (± 0.60%)-0.01s (- 0.19%)3.16s3.25s
Total Time11.30s (± 0.28%)11.30s (± 0.20%)-0.01s (- 0.04%)11.25s11.36s
TFS - node (v10.16.3, x64)
Memory used305,299k (± 0.02%)305,302k (± 0.03%)+3k (+ 0.00%)305,020k305,577k
Parse Time1.28s (± 0.78%)1.28s (± 0.63%)-0.01s (- 0.47%)1.26s1.30s
Bind Time0.72s (± 0.77%)0.71s (± 1.41%)-0.01s (- 0.97%)0.69s0.74s
Check Time5.25s (± 0.69%)5.25s (± 0.45%)-0.00s (- 0.04%)5.20s5.30s
Emit Time3.43s (± 1.10%)3.43s (± 1.93%)-0.00s (- 0.12%)3.31s3.55s
Total Time10.69s (± 0.50%)10.67s (± 0.57%)-0.02s (- 0.15%)10.52s10.79s
material-ui - node (v10.16.3, x64)
Memory used469,833k (± 0.01%)469,821k (± 0.01%)-12k (- 0.00%)469,676k469,966k
Parse Time1.81s (± 0.49%)1.81s (± 0.42%)+0.01s (+ 0.39%)1.80s1.83s
Bind Time0.68s (± 1.13%)0.68s (± 0.98%)+0.00s (+ 0.74%)0.66s0.69s
Check Time14.30s (± 0.56%)14.33s (± 0.64%)+0.03s (+ 0.20%)14.11s14.58s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time16.78s (± 0.48%)16.82s (± 0.55%)+0.04s (+ 0.24%)16.60s17.06s
xstate - node (v10.16.3, x64)
Memory used573,939k (± 1.25%)574,052k (± 1.25%)+113k (+ 0.02%)570,590k602,991k
Parse Time2.57s (± 0.32%)2.58s (± 0.25%)+0.00s (+ 0.16%)2.57s2.59s
Bind Time1.01s (± 0.68%)1.00s (± 0.47%)-0.01s (- 0.60%)0.99s1.01s
Check Time1.51s (± 0.49%)1.51s (± 0.50%)+0.00s (+ 0.07%)1.50s1.53s
Emit Time0.07s (± 4.13%)0.07s (± 0.00%)-0.00s (- 2.78%)0.07s0.07s
Total Time5.16s (± 0.23%)5.16s (± 0.21%)+0.00s (+ 0.04%)5.14s5.18s
Angular - node (v12.1.0, x64)
Memory used334,451k (± 0.01%)334,509k (± 0.02%)+57k (+ 0.02%)334,413k334,692k
Parse Time2.04s (± 0.69%)2.04s (± 0.24%)-0.01s (- 0.29%)2.03s2.05s
Bind Time0.82s (± 0.36%)0.83s (± 1.23%)+0.01s (+ 1.09%)0.82s0.86s
Check Time5.67s (± 1.00%)5.65s (± 0.50%)-0.01s (- 0.26%)5.61s5.73s
Emit Time6.26s (± 0.56%)6.25s (± 0.32%)-0.00s (- 0.02%)6.21s6.29s
Total Time14.78s (± 0.64%)14.77s (± 0.27%)-0.01s (- 0.05%)14.71s14.90s
Compiler-Unions - node (v12.1.0, x64)
Memory used193,168k (± 0.12%)193,167k (± 0.12%)-1k (- 0.00%)192,735k193,461k
Parse Time0.84s (± 0.53%)0.84s (± 0.81%)+0.01s (+ 0.72%)0.83s0.86s
Bind Time0.53s (± 0.68%)0.53s (± 0.84%)-0.00s (- 0.37%)0.52s0.54s
Check Time7.42s (± 0.33%)7.49s (± 0.52%)+0.07s (+ 0.88%)7.39s7.56s
Emit Time2.57s (± 1.45%)2.57s (± 2.28%)+0.00s (+ 0.12%)2.49s2.79s
Total Time11.36s (± 0.47%)11.43s (± 0.70%)+0.07s (+ 0.64%)11.31s11.71s
Monaco - node (v12.1.0, x64)
Memory used326,574k (± 0.08%)326,581k (± 0.06%)+7k (+ 0.00%)325,870k326,784k
Parse Time1.55s (± 0.40%)1.55s (± 0.86%)+0.00s (+ 0.26%)1.52s1.58s
Bind Time0.74s (± 1.10%)0.74s (± 0.54%)+0.00s (+ 0.14%)0.73s0.75s
Check Time5.61s (± 0.62%)5.60s (± 0.36%)-0.00s (- 0.09%)5.56s5.64s
Emit Time3.28s (± 1.34%)3.27s (± 0.88%)-0.01s (- 0.30%)3.23s3.36s
Total Time11.18s (± 0.63%)11.17s (± 0.36%)-0.01s (- 0.05%)11.12s11.29s
TFS - node (v12.1.0, x64)
Memory used289,873k (± 0.06%)289,915k (± 0.01%)+42k (+ 0.01%)289,838k289,988k
Parse Time1.29s (± 0.76%)1.29s (± 0.59%)-0.00s (- 0.16%)1.27s1.30s
Bind Time0.71s (± 0.73%)0.71s (± 0.85%)-0.00s (- 0.56%)0.69s0.72s
Check Time5.18s (± 0.58%)5.19s (± 0.39%)+0.00s (+ 0.08%)5.15s5.25s
Emit Time3.45s (± 1.07%)3.47s (± 0.70%)+0.02s (+ 0.43%)3.38s3.50s
Total Time10.63s (± 0.43%)10.64s (± 0.34%)+0.01s (+ 0.14%)10.52s10.69s
material-ui - node (v12.1.0, x64)
Memory used448,864k (± 0.06%)448,825k (± 0.07%)-38k (- 0.01%)447,640k449,078k
Parse Time1.81s (± 0.33%)1.80s (± 0.37%)-0.00s (- 0.28%)1.79s1.82s
Bind Time0.64s (± 0.52%)0.64s (± 0.69%)+0.00s (+ 0.31%)0.63s0.65s
Check Time12.90s (± 0.68%)12.85s (± 0.43%)-0.04s (- 0.32%)12.77s12.99s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.34s (± 0.55%)15.30s (± 0.41%)-0.04s (- 0.29%)15.21s15.45s
xstate - node (v12.1.0, x64)
Memory used536,345k (± 0.02%)536,294k (± 0.01%)-51k (- 0.01%)536,132k536,430k
Parse Time2.52s (± 0.56%)2.51s (± 0.55%)-0.01s (- 0.44%)2.48s2.54s
Bind Time1.03s (± 0.46%)1.03s (± 0.64%)-0.00s (- 0.29%)1.02s1.04s
Check Time1.47s (± 0.41%)1.46s (± 0.64%)-0.01s (- 0.34%)1.44s1.48s
Emit Time0.07s (± 0.00%)0.07s (± 0.00%)0.00s ( 0.00%)0.07s0.07s
Total Time5.09s (± 0.33%)5.07s (± 0.26%)-0.02s (- 0.39%)5.05s5.11s
Angular - node (v14.15.1, x64)
Memory used332,666k (± 0.08%)332,806k (± 0.01%)+140k (+ 0.04%)332,771k332,851k
Parse Time2.02s (± 0.77%)2.02s (± 0.35%)-0.00s (- 0.05%)2.00s2.03s
Bind Time0.86s (± 0.57%)0.87s (± 0.57%)+0.00s (+ 0.23%)0.86s0.88s
Check Time5.65s (± 0.63%)5.63s (± 0.30%)-0.02s (- 0.32%)5.58s5.66s
Emit Time6.32s (± 0.73%)6.31s (± 0.57%)-0.01s (- 0.14%)6.22s6.38s
Total Time14.85s (± 0.52%)14.83s (± 0.28%)-0.02s (- 0.13%)14.73s14.92s
Compiler-Unions - node (v14.15.1, x64)
Memory used194,015k (± 0.61%)194,628k (± 0.50%)+614k (+ 0.32%)191,993k195,378k
Parse Time0.86s (± 0.68%)0.86s (± 0.61%)+0.00s (+ 0.23%)0.85s0.87s
Bind Time0.56s (± 0.65%)0.56s (± 0.80%)+0.00s (+ 0.36%)0.55s0.57s
Check Time7.49s (± 0.59%)7.52s (± 0.79%)+0.04s (+ 0.47%)7.39s7.72s
Emit Time2.51s (± 0.86%)2.50s (± 0.92%)-0.01s (- 0.36%)2.46s2.55s
Total Time11.41s (± 0.39%)11.44s (± 0.58%)+0.03s (+ 0.26%)11.32s11.64s
Monaco - node (v14.15.1, x64)
Memory used325,399k (± 0.00%)325,402k (± 0.00%)+3k (+ 0.00%)325,372k325,429k
Parse Time1.58s (± 0.55%)1.57s (± 0.66%)-0.01s (- 0.63%)1.55s1.59s
Bind Time0.77s (± 0.58%)0.78s (± 0.48%)+0.00s (+ 0.39%)0.77s0.78s
Check Time5.51s (± 0.43%)5.51s (± 0.56%)-0.00s (- 0.04%)5.46s5.58s
Emit Time3.30s (± 0.59%)3.31s (± 0.68%)+0.01s (+ 0.33%)3.26s3.36s
Total Time11.16s (± 0.24%)11.16s (± 0.34%)-0.00s (- 0.00%)11.08s11.24s
TFS - node (v14.15.1, x64)
Memory used288,906k (± 0.01%)288,903k (± 0.01%)-3k (- 0.00%)288,866k288,949k
Parse Time1.33s (± 2.11%)1.31s (± 0.56%)-0.02s (- 1.88%)1.30s1.33s
Bind Time0.73s (± 0.76%)0.73s (± 0.81%)+0.00s (+ 0.41%)0.72s0.75s
Check Time5.17s (± 0.27%)5.17s (± 0.74%)+0.01s (+ 0.19%)5.08s5.28s
Emit Time3.51s (± 2.04%)3.50s (± 1.87%)-0.01s (- 0.26%)3.38s3.62s
Total Time10.74s (± 0.75%)10.72s (± 0.87%)-0.02s (- 0.20%)10.51s10.93s
material-ui - node (v14.15.1, x64)
Memory used447,018k (± 0.08%)447,143k (± 0.07%)+125k (+ 0.03%)445,962k447,324k
Parse Time1.85s (± 0.45%)1.86s (± 0.42%)+0.01s (+ 0.32%)1.85s1.88s
Bind Time0.70s (± 0.79%)0.70s (± 1.16%)+0.00s (+ 0.14%)0.69s0.72s
Check Time13.07s (± 0.76%)13.01s (± 0.95%)-0.07s (- 0.50%)12.88s13.48s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.63s (± 0.63%)15.57s (± 0.83%)-0.06s (- 0.36%)15.43s16.07s
xstate - node (v14.15.1, x64)
Memory used534,078k (± 0.00%)534,070k (± 0.00%)-8k (- 0.00%)534,014k534,104k
Parse Time2.58s (± 0.52%)2.56s (± 0.36%)-0.02s (- 0.81%)2.54s2.58s
Bind Time1.16s (± 1.04%)1.14s (± 0.87%)-0.01s (- 1.12%)1.12s1.16s
Check Time1.50s (± 0.45%)1.50s (± 0.27%)-0.00s (- 0.27%)1.49s1.51s
Emit Time0.07s (± 0.00%)0.07s (± 0.00%)0.00s ( 0.00%)0.07s0.07s
Total Time5.31s (± 0.32%)5.28s (± 0.26%)-0.03s (- 0.58%)5.25s5.31s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory3 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)
BenchmarkNameIterations
Current4849010
Baselinemain10

Developer Information:

Download Benchmark

@jakebailey
Jake Bailey (jakebailey) merged commit 3c6c279 into microsoft:mainMar 30, 2022
@jakebailey
Jake Bailey (jakebailey) deleted the fix-48379 branch March 30, 2022 22:33
Sidharth Vinod (sidharthv96) added a commit to sidharthv96/TypeScript that referenced this pull request Apr 1, 2022
* upstream/main: (473 commits)
Correct node used for isDefinition calculation (microsoft#48499)
fix(48405): emit dummy members from a mapped type (microsoft#48481)
CFA for dependent parameters typed by generic constraints (microsoft#48411)
No contextual typing from return types for boolean literals (microsoft#48380)
fix(47733): omit JSDoc comment template suggestion on node with existing JSDoc (microsoft#47748)
Ensure that we copy empty NodeArrays during transform (microsoft#48490)
Add a new compiler option `moduleSuffixes` to expand the node module resolver's search algorithm (microsoft#48189)
feat(27615): Add missing member fix should work for type literals (microsoft#47212)
Add label details to completion entry (microsoft#48429)
Enable method signature completion for object literals (microsoft#48168)
Fix string literal completions when a partially-typed string fixes inference to a type parameter (microsoft#48410)
fix(48445): show errors on type-only import/export specifiers in JavaScript files (microsoft#48449)
Fix newline inserted in empty block at end of formatting range (microsoft#48463)
Prevent looking up symbol for as const from triggering an error (microsoft#48464)
Revise accessor resolution logic and error reporting (microsoft#48459)
fix(48166): skip checking module.exports in a truthiness call expression (microsoft#48337)
LEGO: Merge pull request 48450
LEGO: Merge pull request 48436
fix(48031): show circularity error for self referential get accessor annotations (microsoft#48050)
Revert "Fix contextual discrimination for omitted members (microsoft#43937)" (microsoft#48426)
...
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: TeamFor Milestone BugPRs that fix a bug with a specific milestone

Projects

None yet

4 participants

@jakebailey@typescript-bot@weswigham@gabritto