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

Node builder scope traversal improvements #58063

Merged

Conversation

weswigham
Copy link
Member

This PR adjusts scope lookups in the node builder to handle entering and existing scopes for signature, mapped type, and conditional type nodes - this way types which contain references to things defined in those scopes (usually type parameters) can be appropriately reused.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Apr 3, 2024
Comment on lines 429 to +430
>makeRecord : <T, K extends string>(obj: { [P in K]: T; }) => { [P in K]: T; }
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^^
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^
Copy link
Member

Choose a reason for hiding this comment

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

Here too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Previously the argument mapped type and return mapped type shared a scope, so when we generated the P in the argument, we'd see the same type P in the return position and reuse it. Now, we exit the scope and discard the name, and generate a new one from the type for the return mapped type 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.

(Do note: the return here is inferred - there are no direct input nodes)

Copy link
Member

Choose a reason for hiding this comment

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

Hm, alrighty.

@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 3, 2024

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

Command Status Results
test top400 ✅ Started ✅ Results
user test this ✅ Started ✅ Results
run dt ✅ Started ✅ Results
perf test this faster ✅ Started 👀 Results

Comment on lines +7680 to +7694
const node = kind === SyntaxKind.CallSignature ? factory.createCallSignature(typeParameters, parameters, returnTypeNode) :
kind === SyntaxKind.ConstructSignature ? factory.createConstructSignature(typeParameters, parameters, returnTypeNode) :
kind === SyntaxKind.MethodSignature ? factory.createMethodSignature(modifiers, options?.name ?? factory.createIdentifier(""), options?.questionToken, typeParameters, parameters, returnTypeNode) :
kind === SyntaxKind.MethodDeclaration ? factory.createMethodDeclaration(modifiers, /*asteriskToken*/ undefined, options?.name ?? factory.createIdentifier(""), /*questionToken*/ undefined, typeParameters, parameters, returnTypeNode, /*body*/ undefined) :
kind === SyntaxKind.Constructor ? factory.createConstructorDeclaration(modifiers, parameters, /*body*/ undefined) :
kind === SyntaxKind.GetAccessor ? factory.createGetAccessorDeclaration(modifiers, options?.name ?? factory.createIdentifier(""), parameters, returnTypeNode, /*body*/ undefined) :
kind === SyntaxKind.SetAccessor ? factory.createSetAccessorDeclaration(modifiers, options?.name ?? factory.createIdentifier(""), parameters, /*body*/ undefined) :
kind === SyntaxKind.IndexSignature ? factory.createIndexSignature(modifiers, parameters, returnTypeNode) :
kind === SyntaxKind.JSDocFunctionType ? factory.createJSDocFunctionType(parameters, returnTypeNode) :
kind === SyntaxKind.FunctionType ? factory.createFunctionTypeNode(typeParameters, parameters, returnTypeNode ?? factory.createTypeReferenceNode(factory.createIdentifier(""))) :
kind === SyntaxKind.ConstructorType ? factory.createConstructorTypeNode(modifiers, typeParameters, parameters, returnTypeNode ?? factory.createTypeReferenceNode(factory.createIdentifier(""))) :
kind === SyntaxKind.FunctionDeclaration ? factory.createFunctionDeclaration(modifiers, /*asteriskToken*/ undefined, options?.name ? cast(options.name, isIdentifier) : factory.createIdentifier(""), typeParameters, parameters, returnTypeNode, /*body*/ undefined) :
kind === SyntaxKind.FunctionExpression ? factory.createFunctionExpression(modifiers, /*asteriskToken*/ undefined, options?.name ? cast(options.name, isIdentifier) : factory.createIdentifier(""), typeParameters, parameters, returnTypeNode, factory.createBlock([])) :
kind === SyntaxKind.ArrowFunction ? factory.createArrowFunction(modifiers, typeParameters, parameters, returnTypeNode, /*equalsGreaterThanToken*/ undefined, factory.createBlock([])) :
Debug.assertNever(kind);
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 preexisting, but I sure wonder why this isn't just a big switch 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

🤷‍♂️

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user tests comparing main and refs/pull/58063/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

@jakebailey
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
Angular - node (v18.15.0, x64)
Memory used 295,716k (± 0.01%) 295,744k (± 0.01%) ~ 295,684k 295,780k p=0.298 n=6
Parse Time 2.66s (± 0.19%) 2.66s (± 0.39%) ~ 2.65s 2.68s p=0.242 n=6
Bind Time 0.83s (± 0.66%) 0.83s (± 0.66%) ~ 0.83s 0.84s p=1.000 n=6
Check Time 8.24s (± 0.24%) 8.26s (± 0.06%) ~ 8.25s 8.26s p=0.114 n=6
Emit Time 7.07s (± 0.39%) 7.05s (± 0.36%) ~ 7.03s 7.10s p=0.225 n=6
Total Time 18.80s (± 0.25%) 18.80s (± 0.17%) ~ 18.77s 18.86s p=0.746 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 193,878k (± 0.96%) 192,713k (± 0.79%) ~ 192,051k 195,815k p=0.298 n=6
Parse Time 1.36s (± 1.70%) 1.37s (± 1.10%) ~ 1.35s 1.39s p=0.287 n=6
Bind Time 0.73s (± 0.71%) 0.73s (± 0.00%) ~ 0.73s 0.73s p=0.174 n=6
Check Time 9.55s (± 0.44%) 9.53s (± 0.49%) ~ 9.48s 9.59s p=0.293 n=6
Emit Time 2.63s (± 0.52%) 2.63s (± 0.46%) ~ 2.62s 2.65s p=0.410 n=6
Total Time 14.26s (± 0.40%) 14.26s (± 0.31%) ~ 14.20s 14.31s p=0.936 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,414k (± 0.01%) 347,425k (± 0.00%) ~ 347,408k 347,443k p=0.296 n=6
Parse Time 2.48s (± 0.25%) 2.49s (± 0.55%) ~ 2.47s 2.50s p=0.362 n=6
Bind Time 0.93s (± 0.00%) 0.93s (± 0.56%) ~ 0.92s 0.93s p=0.174 n=6
Check Time 6.98s (± 0.28%) 6.99s (± 0.41%) ~ 6.95s 7.03s p=0.373 n=6
Emit Time 4.05s (± 0.19%) 4.07s (± 0.52%) ~ 4.05s 4.11s p=0.063 n=6
Total Time 14.44s (± 0.22%) 14.47s (± 0.15%) ~ 14.44s 14.50s p=0.106 n=6
TFS - node (v18.15.0, x64)
Memory used 302,848k (± 0.01%) 302,835k (± 0.01%) ~ 302,803k 302,894k p=0.378 n=6
Parse Time 2.40s (± 1.03%) 2.41s (± 1.00%) ~ 2.37s 2.43s p=0.571 n=6
Bind Time 1.20s (± 1.05%) 1.19s (± 0.83%) ~ 1.18s 1.20s p=0.137 n=6
Check Time 7.57s (± 0.56%) 7.56s (± 0.41%) ~ 7.51s 7.59s p=0.627 n=6
Emit Time 4.28s (± 0.87%) 4.28s (± 0.61%) ~ 4.26s 4.33s p=0.745 n=6
Total Time 15.45s (± 0.46%) 15.44s (± 0.40%) ~ 15.36s 15.51s p=1.000 n=6
material-ui - node (v18.15.0, x64)
Memory used 510,060k (± 0.01%) 510,064k (± 0.01%) ~ 510,006k 510,126k p=1.000 n=6
Parse Time 2.66s (± 0.24%) 2.66s (± 0.39%) ~ 2.65s 2.67s p=0.443 n=6
Bind Time 0.99s (± 0.52%) 0.99s (± 0.76%) ~ 0.98s 1.00s p=0.241 n=6
Check Time 17.31s (± 0.48%) 17.32s (± 0.36%) ~ 17.26s 17.40s p=0.936 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.96s (± 0.41%) 20.97s (± 0.30%) ~ 20.91s 21.05s p=1.000 n=6
mui-docs - node (v18.15.0, x64)
Memory used 1,744,946k (± 0.00%) 1,744,960k (± 0.00%) ~ 1,744,897k 1,745,034k p=0.423 n=6
Parse Time 9.64s (± 0.65%) 9.64s (± 0.65%) ~ 9.58s 9.76s p=1.000 n=6
Bind Time 3.47s (± 0.46%) 3.46s (± 0.81%) ~ 3.41s 3.49s p=0.411 n=6
Check Time 81.73s (± 0.35%) 82.00s (± 0.43%) ~ 81.40s 82.38s p=0.230 n=6
Emit Time 0.19s (± 2.67%) 0.19s (± 0.00%) ~ 0.19s 0.19s p=0.174 n=6
Total Time 95.03s (± 0.33%) 95.28s (± 0.33%) ~ 94.82s 95.70s p=0.173 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,400,823k (± 0.05%) 2,401,519k (± 0.02%) ~ 2,400,924k 2,402,381k p=0.471 n=6
Parse Time 7.53s (± 0.99%) 7.48s (± 0.76%) ~ 7.43s 7.57s p=0.298 n=6
Bind Time 2.77s (± 1.06%) 2.79s (± 0.37%) ~ 2.78s 2.81s p=0.296 n=6
Check Time 49.52s (± 0.44%) 49.38s (± 0.35%) ~ 49.21s 49.65s p=0.298 n=6
Emit Time 3.92s (± 1.38%) 3.94s (± 1.55%) ~ 3.85s 4.04s p=0.810 n=6
Total Time 63.75s (± 0.39%) 63.60s (± 0.34%) ~ 63.35s 63.84s p=0.575 n=6
self-compiler - node (v18.15.0, x64)
Memory used 416,180k (± 0.01%) 416,323k (± 0.01%) +144k (+ 0.03%) 416,288k 416,351k p=0.005 n=6
Parse Time 4.12s (± 0.54%) 4.14s (± 0.62%) ~ 4.10s 4.16s p=0.131 n=6
Bind Time 1.58s (± 1.11%) 1.59s (± 0.95%) ~ 1.58s 1.62s p=0.357 n=6
Check Time 22.50s (± 0.35%) 22.50s (± 0.53%) ~ 22.40s 22.67s p=0.936 n=6
Emit Time 1.66s (± 1.96%) 1.68s (± 1.50%) ~ 1.66s 1.72s p=0.414 n=6
Total Time 29.86s (± 0.23%) 29.92s (± 0.43%) ~ 29.80s 30.10s p=0.630 n=6
vscode - node (v18.15.0, x64)
Memory used 2,900,677k (± 0.00%) 2,900,673k (± 0.00%) ~ 2,900,491k 2,900,762k p=0.689 n=6
Parse Time 15.97s (± 0.25%) 15.96s (± 0.32%) ~ 15.91s 16.03s p=0.629 n=6
Bind Time 5.06s (± 0.40%) 5.08s (± 0.44%) ~ 5.06s 5.11s p=0.096 n=6
Check Time 87.75s (± 0.44%) 87.70s (± 1.05%) ~ 86.51s 88.79s p=0.810 n=6
Emit Time 24.47s (± 8.03%) 25.38s (± 9.73%) ~ 23.64s 28.68s p=0.229 n=6
Total Time 133.24s (± 1.58%) 134.12s (± 2.46%) ~ 131.31s 138.44s p=0.936 n=6
webpack - node (v18.15.0, x64)
Memory used 408,951k (± 0.01%) 409,008k (± 0.01%) ~ 408,946k 409,092k p=0.093 n=6
Parse Time 4.80s (± 0.48%) 4.79s (± 0.89%) ~ 4.76s 4.87s p=0.255 n=6
Bind Time 2.07s (± 0.64%) 2.05s (± 0.72%) ~ 2.04s 2.07s p=0.094 n=6
Check Time 20.85s (± 0.48%) 20.97s (± 0.51%) ~ 20.87s 21.11s p=0.127 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 27.71s (± 0.38%) 27.82s (± 0.33%) ~ 27.67s 27.91s p=0.126 n=6
xstate - node (v18.15.0, x64)
Memory used 513,600k (± 0.03%) 513,553k (± 0.02%) ~ 513,400k 513,737k p=0.575 n=6
Parse Time 4.87s (± 0.65%) 4.90s (± 0.42%) ~ 4.87s 4.93s p=0.253 n=6
Bind Time 2.30s (± 1.08%) 2.31s (± 1.04%) ~ 2.27s 2.34s p=0.466 n=6
Check Time 4.31s (± 1.09%) 4.31s (± 1.38%) ~ 4.24s 4.38s p=0.873 n=6
Emit Time 0.11s (± 0.00%) 0.11s (± 0.00%) ~ 0.11s 0.11s p=1.000 n=6
Total Time 11.60s (± 0.44%) 11.62s (± 0.71%) ~ 11.51s 11.72s p=0.328 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@weswigham weswigham merged commit 82897a0 into microsoft:main Apr 3, 2024
25 checks passed
@weswigham weswigham deleted the node-builder-scope-traversal-improvements branch April 3, 2024 21:35
@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top 400 repos comparing main and refs/pull/58063/merge:

Everything looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants