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

Fix name generation scoping #58418

Merged
merged 2 commits into from May 6, 2024
Merged

Fix name generation scoping #58418

merged 2 commits into from May 6, 2024

Conversation

rbuckton
Copy link
Member

@rbuckton rbuckton commented May 2, 2024

There are a number of small oddities in the emitter regarding name generation for temp variables and private names. Despite using reservedNames/reservedPrivateNames to reserve names permanently within a scope, we weren't checking all reservations in the respective stacks. We also weren't consistent about name generation in a few places, so I've combined the private and temp variable name scopes so that we enter and exit both consistently.

I also removed a place where we exited and then reentered a private name generation scope when visiting a computed property name since both temp variables and private names should be generated immediately as we enter a declaration, not on-demand as we descend into and out of computed property names.

Fixes #57897

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels May 2, 2024
@DanielRosenwasser
Copy link
Member

@typescript-bot perf test this faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented May 2, 2024

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

Command Status Results
perf test this faster ✅ Started 👀 Results

Comment on lines +5367 to +5369
if (set === stack[i]) {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

This is partially off-topic, but is there any reason the current scope can't be stored separate of the stack itself? Or if it is possible, when is it the case that the current is not the same as the last in the stack?

Copy link
Member Author

Choose a reason for hiding this comment

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

The current scope is stored separate from the stack. The way push/pop works is that we don't reset the current scope until we actually record something so that we defer the cost of reassignment until the moment we actually need to record a name. This check here is an example of that. If the set for the current scope is also in the stack, then we can skip it as nothing else was actually recorded in that scope.

Copy link
Member Author

Choose a reason for hiding this comment

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

In other words, the algorithm favors code that requires no generated names so that we can avoid paying the cost for more recent --targets.

@typescript-bot
Copy link
Collaborator

@DanielRosenwasser
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
Compiler-Unions - node (v18.15.0, x64)
Errors 30 30 ~ ~ ~ p=1.000 n=6
Symbols 62,154 62,154 ~ ~ ~ p=1.000 n=6
Types 50,273 50,273 ~ ~ ~ p=1.000 n=6
Memory used 192,937k (± 0.74%) 192,889k (± 0.74%) ~ 192,207k 195,790k p=0.810 n=6
Parse Time 1.30s (± 0.65%) 1.30s (± 0.40%) ~ 1.30s 1.31s p=0.070 n=6
Bind Time 0.72s 0.72s ~ ~ ~ p=1.000 n=6
Check Time 9.56s (± 0.36%) 9.54s (± 0.32%) ~ 9.51s 9.59s p=0.468 n=6
Emit Time 2.64s (± 0.52%) 2.65s (± 0.40%) ~ 2.63s 2.66s p=0.249 n=6
Total Time 14.21s (± 0.27%) 14.21s (± 0.22%) ~ 14.18s 14.25s p=1.000 n=6
angular-1 - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 945,322 945,322 ~ ~ ~ p=1.000 n=6
Types 408,088 408,088 ~ ~ ~ p=1.000 n=6
Memory used 1,222,809k (± 0.01%) 1,222,768k (± 0.00%) ~ 1,222,717k 1,222,816k p=0.128 n=6
Parse Time 6.77s (± 0.49%) 6.78s (± 0.83%) ~ 6.73s 6.89s p=1.000 n=6
Bind Time 1.88s (± 0.71%) 1.87s (± 0.83%) ~ 1.84s 1.88s p=0.491 n=6
Check Time 31.43s (± 0.38%) 31.38s (± 0.63%) ~ 31.16s 31.67s p=0.575 n=6
Emit Time 14.69s (± 0.38%) 14.78s (± 0.18%) +0.10s (+ 0.65%) 14.76s 14.82s p=0.005 n=6
Total Time 54.76s (± 0.31%) 54.81s (± 0.27%) ~ 54.64s 55.04s p=0.810 n=6
mui-docs - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 1,956,843 1,956,843 ~ ~ ~ p=1.000 n=6
Types 676,446 676,446 ~ ~ ~ p=1.000 n=6
Memory used 1,764,741k (± 0.00%) 1,764,764k (± 0.00%) ~ 1,764,719k 1,764,789k p=0.230 n=6
Parse Time 6.70s (± 0.44%) 6.68s (± 0.15%) ~ 6.67s 6.69s p=0.290 n=6
Bind Time 2.31s (± 0.39%) 2.32s (± 0.42%) ~ 2.31s 2.34s p=0.070 n=6
Check Time 56.28s (± 0.28%) 56.13s (± 0.63%) ~ 55.74s 56.71s p=0.170 n=6
Emit Time 0.14s (± 2.88%) 0.14s ~ ~ ~ p=0.405 n=6
Total Time 65.43s (± 0.26%) 65.27s (± 0.53%) ~ 64.87s 65.84s p=0.378 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,217,318 1,217,380 +62 (+ 0.01%) ~ ~ p=0.001 n=6
Types 258,271 258,303 +32 (+ 0.01%) ~ ~ p=0.001 n=6
Memory used 2,327,426k (± 0.01%) 2,327,437k (± 0.03%) ~ 2,326,606k 2,328,590k p=0.575 n=6
Parse Time 4.93s (± 0.92%) 4.99s (± 1.24%) ~ 4.92s 5.09s p=0.066 n=6
Bind Time 1.87s (± 1.11%) 1.87s (± 0.71%) ~ 1.86s 1.89s p=0.622 n=6
Check Time 33.41s (± 0.39%) 33.38s (± 0.42%) ~ 33.23s 33.56s p=0.810 n=6
Emit Time 2.62s (± 0.76%) 2.60s (± 3.14%) ~ 2.47s 2.72s p=0.468 n=6
Total Time 42.82s (± 0.34%) 42.84s (± 0.38%) ~ 42.66s 43.07s p=0.873 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,217,318 1,217,380 +62 (+ 0.01%) ~ ~ p=0.001 n=6
Types 258,271 258,303 +32 (+ 0.01%) ~ ~ p=0.001 n=6
Memory used 2,402,366k (± 0.01%) 2,403,021k (± 0.02%) ~ 2,402,291k 2,403,672k p=0.093 n=6
Parse Time 6.17s (± 0.82%) 6.19s (± 1.27%) ~ 6.10s 6.31s p=0.748 n=6
Bind Time 2.01s (± 0.98%) 2.01s (± 0.60%) ~ 2.00s 2.03s p=0.366 n=6
Check Time 39.97s (± 0.31%) 39.93s (± 0.36%) ~ 39.69s 40.07s p=0.689 n=6
Emit Time 3.10s (± 0.88%) 3.09s (± 2.40%) ~ 3.00s 3.18s p=0.936 n=6
Total Time 51.25s (± 0.31%) 51.24s (± 0.26%) ~ 51.08s 51.48s p=0.936 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 256,297 256,356 +59 (+ 0.02%) ~ ~ p=0.001 n=6
Types 103,722 103,747 +25 (+ 0.02%) ~ ~ p=0.001 n=6
Memory used 424,301k (± 0.00%) 424,346k (± 0.01%) +45k (+ 0.01%) 424,286k 424,378k p=0.045 n=6
Parse Time 4.16s (± 0.94%) 4.17s (± 0.77%) ~ 4.11s 4.20s p=0.808 n=6
Bind Time 1.59s (± 1.08%) 1.60s (± 1.18%) ~ 1.57s 1.62s p=0.366 n=6
Check Time 21.91s (± 0.31%) 21.93s (± 0.39%) ~ 21.78s 22.01s p=0.470 n=6
Emit Time 1.72s (± 0.97%) 1.73s (± 2.05%) ~ 1.67s 1.77s p=0.361 n=6
Total Time 29.38s (± 0.20%) 29.43s (± 0.28%) ~ 29.30s 29.51s p=0.226 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 35 35 ~ ~ ~ p=1.000 n=6
Symbols 224,824 224,824 ~ ~ ~ p=1.000 n=6
Types 93,390 93,390 ~ ~ ~ p=1.000 n=6
Memory used 369,286k (± 0.01%) 369,361k (± 0.03%) ~ 369,292k 369,601k p=0.065 n=6
Parse Time 2.85s (± 1.07%) 2.84s (± 1.13%) ~ 2.79s 2.88s p=0.467 n=6
Bind Time 1.59s (± 0.79%) 1.58s (± 0.65%) ~ 1.56s 1.59s p=0.099 n=6
Check Time 15.60s (± 0.27%) 15.63s (± 0.45%) ~ 15.56s 15.76s p=0.574 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.04s (± 0.15%) 20.05s (± 0.28%) ~ 20.00s 20.14s p=1.000 n=6
vscode - node (v18.15.0, x64)
Errors 4 4 ~ ~ ~ p=1.000 n=6
Symbols 2,802,214 2,802,214 ~ ~ ~ p=1.000 n=6
Types 951,821 951,821 ~ ~ ~ p=1.000 n=6
Memory used 2,956,206k (± 0.00%) 2,956,239k (± 0.00%) ~ 2,956,197k 2,956,301k p=0.575 n=6
Parse Time 13.58s (± 0.20%) 13.58s (± 0.33%) ~ 13.51s 13.62s p=1.000 n=6
Bind Time 4.10s (± 0.32%) 4.09s (± 0.13%) ~ 4.09s 4.10s p=0.546 n=6
Check Time 72.80s (± 0.52%) 72.95s (± 0.33%) ~ 72.55s 73.29s p=0.575 n=6
Emit Time 23.71s (± 1.10%) 23.61s (± 0.49%) ~ 23.44s 23.80s p=0.687 n=6
Total Time 114.19s (± 0.48%) 114.22s (± 0.19%) ~ 114.03s 114.64s p=1.000 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 265,858 265,858 ~ ~ ~ p=1.000 n=6
Types 108,442 108,442 ~ ~ ~ p=1.000 n=6
Memory used 410,400k (± 0.01%) 410,407k (± 0.02%) ~ 410,331k 410,505k p=0.936 n=6
Parse Time 4.75s (± 1.04%) 4.74s (± 0.53%) ~ 4.70s 4.77s p=0.746 n=6
Bind Time 2.08s (± 0.47%) 2.08s (± 1.03%) ~ 2.05s 2.10s p=1.000 n=6
Check Time 20.95s (± 0.50%) 20.95s (± 0.28%) ~ 20.85s 21.03s p=1.000 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 27.78s (± 0.38%) 27.77s (± 0.25%) ~ 27.67s 27.82s p=1.000 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 524,146 524,146 ~ ~ ~ p=1.000 n=6
Types 178,732 178,732 ~ ~ ~ p=1.000 n=6
Memory used 462,221k (± 0.02%) 462,229k (± 0.02%) ~ 462,103k 462,314k p=1.000 n=6
Parse Time 3.86s (± 0.39%) 3.89s (± 0.73%) ~ 3.86s 3.93s p=0.166 n=6
Bind Time 1.47s (± 1.05%) 1.46s (± 0.83%) ~ 1.44s 1.47s p=0.183 n=6
Check Time 22.49s (± 0.49%) 22.39s (± 0.60%) ~ 22.14s 22.51s p=0.226 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 27.82s (± 0.40%) 27.74s (± 0.41%) ~ 27.53s 27.84s p=0.377 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@rbuckton rbuckton merged commit 70d8ec2 into main May 6, 2024
28 checks passed
@rbuckton rbuckton deleted the fix-57897 branch May 6, 2024 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
4 participants