Skip to content

Cache property name widening contexts - #40732

Closed
Andrew Casey (amcasey) wants to merge 1 commit into
microsoft:masterfrom
amcasey:WideningContextCache
Closed

Cache property name widening contexts#40732
Andrew Casey (amcasey) wants to merge 1 commit into
microsoft:masterfrom
amcasey:WideningContextCache

Conversation

@amcasey

Copy link
Copy Markdown
Member

When creating a new WideningContext for a given property, check whether
there's an existing WideningContext with the same parent and
propertyName. Otherwise, we won't adequately leverage the cache of
computed siblings stored on the WideningContext.

On my box, check time drops from 10 seconds to 0.3 seconds for this example.

When creating a new `WideningContext` for a given property, check whether
there's an existing `WideningContext` with the same `parent` and
`propertyName`. Otherwise, we won't adequately leverage the cache of
computed `siblings` stored on the `WideningContext`.
@amcasey

Copy link
Copy Markdown
MemberAuthor

TypeScript Bot (@typescript-bot) perf test this

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 24, 2020

Copy link
Copy Markdown
Contributor

Heya Andrew Casey (@amcasey), I've started to run the perf test suite on this PR at 647421f. You can monitor the build here.

Update: The results are in!

@amcasey

Copy link
Copy Markdown
MemberAuthor

Here's a cleaned up and annotated repro.

@typescript-bot

Copy link
Copy Markdown
Contributor

Andrew Casey (@amcasey)
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..40732

Metricmaster40732DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used349,562k (± 0.02%)349,600k (± 0.02%)+38k (+ 0.01%)349,512k349,747k
Parse Time2.01s (± 0.64%)2.00s (± 0.82%)-0.01s (- 0.50%)1.97s2.03s
Bind Time0.83s (± 1.00%)0.83s (± 0.84%)+0.01s (+ 0.61%)0.82s0.85s
Check Time4.90s (± 0.72%)4.93s (± 0.82%)+0.03s (+ 0.63%)4.85s5.04s
Emit Time5.22s (± 1.07%)5.21s (± 0.57%)-0.01s (- 0.19%)5.15s5.27s
Total Time12.95s (± 0.63%)12.97s (± 0.56%)+0.02s (+ 0.12%)12.84s13.17s
Monaco - node (v10.16.3, x64)
Memory used354,401k (± 0.03%)354,335k (± 0.02%)-66k (- 0.02%)354,145k354,478k
Parse Time1.57s (± 0.80%)1.56s (± 0.44%)-0.02s (- 1.14%)1.54s1.57s
Bind Time0.72s (± 0.93%)0.71s (± 0.42%)-0.00s (- 0.70%)0.71s0.72s
Check Time5.07s (± 0.42%)5.05s (± 0.38%)-0.02s (- 0.32%)5.02s5.12s
Emit Time2.77s (± 0.81%)2.75s (± 0.71%)-0.01s (- 0.47%)2.71s2.81s
Total Time10.13s (± 0.44%)10.07s (± 0.26%)-0.05s (- 0.53%)10.02s10.15s
TFS - node (v10.16.3, x64)
Memory used307,561k (± 0.02%)307,564k (± 0.03%)+3k (+ 0.00%)307,425k307,895k
Parse Time1.22s (± 0.85%)1.22s (± 0.63%)-0.01s (- 0.57%)1.20s1.23s
Bind Time0.67s (± 0.99%)0.67s (± 1.30%)-0.00s (- 0.74%)0.64s0.68s
Check Time4.52s (± 0.52%)4.53s (± 0.53%)+0.01s (+ 0.20%)4.48s4.57s
Emit Time2.90s (± 0.85%)2.89s (± 0.80%)-0.01s (- 0.45%)2.82s2.92s
Total Time9.31s (± 0.39%)9.30s (± 0.39%)-0.01s (- 0.14%)9.20s9.36s
material-ui - node (v10.16.3, x64)
Memory used488,979k (± 0.02%)488,998k (± 0.01%)+20k (+ 0.00%)488,873k489,118k
Parse Time1.98s (± 0.47%)1.98s (± 0.33%)+0.00s (+ 0.10%)1.97s1.99s
Bind Time0.65s (± 0.76%)0.65s (± 0.95%)+0.00s (+ 0.46%)0.63s0.66s
Check Time13.43s (± 0.58%)13.42s (± 0.41%)-0.01s (- 0.07%)13.35s13.55s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time16.06s (± 0.53%)16.05s (± 0.38%)-0.00s (- 0.02%)15.96s16.20s
Angular - node (v12.1.0, x64)
Memory used326,813k (± 0.02%)326,830k (± 0.02%)+17k (+ 0.01%)326,700k326,970k
Parse Time2.00s (± 0.47%)2.00s (± 0.41%)-0.00s (- 0.15%)1.98s2.02s
Bind Time0.81s (± 0.64%)0.81s (± 0.64%)+0.00s (+ 0.25%)0.80s0.82s
Check Time4.78s (± 0.46%)4.79s (± 0.61%)+0.01s (+ 0.23%)4.76s4.90s
Emit Time5.33s (± 0.61%)5.35s (± 0.41%)+0.02s (+ 0.38%)5.30s5.39s
Total Time12.92s (± 0.31%)12.95s (± 0.36%)+0.03s (+ 0.23%)12.85s13.06s
Monaco - node (v12.1.0, x64)
Memory used336,487k (± 0.02%)336,522k (± 0.02%)+35k (+ 0.01%)336,389k336,718k
Parse Time1.55s (± 0.82%)1.53s (± 0.82%)-0.01s (- 0.90%)1.51s1.57s
Bind Time0.70s (± 1.09%)0.69s (± 1.67%)-0.00s (- 0.00%)0.68s0.74s
Check Time4.88s (± 0.47%)4.84s (± 0.44%)-0.04s (- 0.76%)4.80s4.90s
Emit Time2.81s (± 0.65%)2.80s (± 0.62%)-0.01s (- 0.25%)2.75s2.83s
Total Time9.93s (± 0.40%)9.87s (± 0.30%)-0.05s (- 0.55%)9.79s9.95s
TFS - node (v12.1.0, x64)
Memory used291,891k (± 0.02%)291,855k (± 0.01%)-36k (- 0.01%)291,774k291,954k
Parse Time1.24s (± 0.70%)1.23s (± 0.76%)-0.00s (- 0.40%)1.21s1.25s
Bind Time0.64s (± 0.62%)0.64s (± 1.13%)+0.00s (+ 0.16%)0.63s0.66s
Check Time4.45s (± 0.38%)4.43s (± 0.48%)-0.02s (- 0.52%)4.39s4.49s
Emit Time2.91s (± 0.85%)2.94s (± 0.70%)+0.02s (+ 0.82%)2.88s2.97s
Total Time9.24s (± 0.38%)9.24s (± 0.30%)-0.01s (- 0.06%)9.15s9.29s
material-ui - node (v12.1.0, x64)
Memory used467,090k (± 0.01%)466,946k (± 0.05%)-143k (- 0.03%)465,988k467,274k
Parse Time2.00s (± 0.57%)2.00s (± 0.63%)-0.00s (- 0.15%)1.97s2.03s
Bind Time0.64s (± 0.77%)0.63s (± 0.57%)-0.00s (- 0.31%)0.63s0.64s
Check Time12.02s (± 0.69%)12.06s (± 1.34%)+0.05s (+ 0.40%)11.81s12.66s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time14.66s (± 0.65%)14.70s (± 1.09%)+0.04s (+ 0.29%)14.45s15.28s
Angular - node (v8.9.0, x64)
Memory used346,294k (± 0.01%)346,277k (± 0.02%)-16k (- 0.00%)346,068k346,423k
Parse Time2.56s (± 0.43%)2.54s (± 0.30%)-0.01s (- 0.51%)2.53s2.56s
Bind Time0.87s (± 0.69%)0.86s (± 0.64%)-0.00s (- 0.46%)0.85s0.88s
Check Time5.53s (± 0.64%)5.54s (± 0.35%)+0.00s (+ 0.04%)5.49s5.57s
Emit Time6.07s (± 1.10%)6.10s (± 2.14%)+0.03s (+ 0.54%)5.87s6.39s
Total Time15.03s (± 0.51%)15.04s (± 0.89%)+0.01s (+ 0.08%)14.79s15.33s
Monaco - node (v8.9.0, x64)
Memory used355,599k (± 0.02%)355,645k (± 0.02%)+45k (+ 0.01%)355,478k355,796k
Parse Time1.88s (± 0.40%)1.89s (± 1.25%)+0.01s (+ 0.53%)1.86s1.98s
Bind Time0.89s (± 0.91%)0.89s (± 0.65%)-0.00s (- 0.34%)0.88s0.90s
Check Time5.61s (± 0.65%)5.57s (± 0.42%)-0.03s (- 0.59%)5.53s5.64s
Emit Time3.28s (± 1.50%)3.27s (± 1.50%)-0.01s (- 0.21%)3.20s3.38s
Total Time11.66s (± 0.40%)11.63s (± 0.56%)-0.03s (- 0.29%)11.50s11.78s
TFS - node (v8.9.0, x64)
Memory used309,269k (± 0.02%)309,285k (± 0.01%)+15k (+ 0.00%)309,207k309,379k
Parse Time1.56s (± 0.58%)1.55s (± 0.31%)-0.00s (- 0.13%)1.54s1.56s
Bind Time0.68s (± 0.49%)0.68s (± 0.73%)-0.00s (- 0.59%)0.67s0.69s
Check Time5.32s (± 0.31%)5.30s (± 0.53%)-0.02s (- 0.38%)5.23s5.37s
Emit Time2.95s (± 0.43%)2.94s (± 0.75%)-0.01s (- 0.44%)2.85s2.96s
Total Time10.50s (± 0.19%)10.46s (± 0.39%)-0.04s (- 0.37%)10.35s10.55s
material-ui - node (v8.9.0, x64)
Memory used493,307k (± 0.01%)493,368k (± 0.01%)+61k (+ 0.01%)493,259k493,426k
Parse Time2.40s (± 0.53%)2.41s (± 0.25%)+0.00s (+ 0.12%)2.39s2.42s
Bind Time0.82s (± 1.09%)0.81s (± 0.99%)-0.00s (- 0.49%)0.79s0.83s
Check Time17.98s (± 0.80%)17.85s (± 0.91%)-0.13s (- 0.75%)17.49s18.15s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time21.20s (± 0.70%)21.07s (± 0.76%)-0.13s (- 0.63%)20.73s21.38s
Angular - node (v8.9.0, x86)
Memory used198,577k (± 0.02%)198,641k (± 0.03%)+65k (+ 0.03%)198,495k198,722k
Parse Time2.47s (± 0.57%)2.48s (± 0.45%)+0.01s (+ 0.45%)2.45s2.50s
Bind Time1.01s (± 0.84%)1.00s (± 0.74%)-0.01s (- 0.59%)0.98s1.01s
Check Time4.99s (± 0.51%)4.98s (± 0.41%)-0.01s (- 0.20%)4.93s5.03s
Emit Time5.89s (± 1.08%)5.92s (± 1.24%)+0.02s (+ 0.42%)5.77s6.05s
Total Time14.36s (± 0.56%)14.39s (± 0.51%)+0.02s (+ 0.15%)14.19s14.52s
Monaco - node (v8.9.0, x86)
Memory used201,404k (± 0.02%)201,414k (± 0.02%)+10k (+ 0.00%)201,305k201,482k
Parse Time1.93s (± 0.84%)1.92s (± 0.68%)-0.01s (- 0.57%)1.90s1.95s
Bind Time0.71s (± 0.63%)0.71s (± 0.99%)+0.00s (+ 0.14%)0.70s0.73s
Check Time5.46s (± 0.86%)5.49s (± 1.10%)+0.02s (+ 0.46%)5.41s5.64s
Emit Time3.01s (± 2.22%)3.00s (± 4.00%)-0.01s (- 0.30%)2.67s3.16s
Total Time11.11s (± 0.36%)11.12s (± 0.68%)+0.01s (+ 0.04%)10.92s11.23s
TFS - node (v8.9.0, x86)
Memory used176,799k (± 0.03%)176,800k (± 0.02%)+1k (+ 0.00%)176,753k176,950k
Parse Time1.59s (± 0.84%)1.59s (± 0.73%)-0.01s (- 0.50%)1.57s1.63s
Bind Time0.64s (± 0.81%)0.64s (± 0.53%)+0.00s (+ 0.31%)0.64s0.65s
Check Time4.81s (± 0.66%)4.80s (± 0.66%)-0.01s (- 0.25%)4.76s4.90s
Emit Time2.82s (± 1.16%)2.80s (± 1.00%)-0.02s (- 0.71%)2.73s2.87s
Total Time9.87s (± 0.59%)9.83s (± 0.36%)-0.04s (- 0.42%)9.75s9.92s
material-ui - node (v8.9.0, x86)
Memory used277,783k (± 0.01%)277,765k (± 0.02%)-19k (- 0.01%)277,610k277,879k
Parse Time2.47s (± 0.79%)2.47s (± 0.82%)+0.01s (+ 0.28%)2.43s2.52s
Bind Time0.72s (± 6.49%)0.71s (± 4.27%)-0.01s (- 1.67%)0.67s0.82s
Check Time16.38s (± 0.57%)16.45s (± 0.75%)+0.07s (+ 0.44%)16.06s16.63s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time19.56s (± 0.49%)19.63s (± 0.52%)+0.07s (+ 0.35%)19.37s19.85s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-166-generic
Architecturex64
Available Memory16 GB
Available Memory1 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v8.9.0, x64)
  • node (v8.9.0, x86)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v8.9.0, x64)
  • Angular - node (v8.9.0, x86)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v8.9.0, x64)
  • Monaco - node (v8.9.0, x86)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v8.9.0, x64)
  • TFS - node (v8.9.0, x86)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v8.9.0, x64)
  • material-ui - node (v8.9.0, x86)
BenchmarkNameIterations
Current4073210
Baselinemaster10

@sandersn

Nathan Shively-Sanders (sandersn) commented Oct 9, 2020

Copy link
Copy Markdown
Member

Andrew Casey (@amcasey) seems like this is ready to merge? Or does it need to wait for 4.2?

@amcasey

Copy link
Copy Markdown
MemberAuthor

Nathan Shively-Sanders (@sandersn) I was saving it for 4.2, but only because there's no rush.

@ahejlsberg

Copy link
Copy Markdown
Member

With #40778 the motivating example no longer creates a large union type, so I wonder if this PR is still worth doing?

@amcasey

Copy link
Copy Markdown
MemberAuthor

Anders Hejlsberg (@ahejlsberg) I'm a little concerned that it'll bite us again in the future if we leave it quadratic, but I agree that there's no urgency. Your call.

@ahejlsberg

Copy link
Copy Markdown
Member

Andrew Casey (@amcasey) The logic only kicks in for fresh object literal types and once #40778 goes in I'm not sure there's anything one would commonly (or even uncommonly) write that generates large unions of fresh object literals. So I vote we hold off.

@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants

@amcasey@typescript-bot@sandersn@ahejlsberg@weswigham