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

Refactor expression evaluator #57955

Merged
merged 2 commits into from
Mar 27, 2024
Merged

Conversation

dragomirtitian
Copy link
Contributor

Refactor expression evaluator to sit outside of the checker.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Mar 27, 2024
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@jakebailey
Copy link
Member

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 27, 2024

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

Command Status Results
perf test this ✅ Started 👀 Results

var evaluate = createEvaluator({
evaluateElementAccessExpression,
evaluateEntityNameExpression,
onNumericLiteral: checkGrammarNumericLiteral,
Copy link
Member

Choose a reason for hiding this comment

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

It feels strange to have this callback. This only needs the AST node and nothing else. Can we just walk the nodes like other grammar checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was trying to introduce as little extra overhead as possible, I agree that callback is kinds of the odd one out, but without an extra walk I'm not sure how we could ensure that check is performed in the same way.

The check does appear to happen in other places though. Enum members should go through checkEnumMember which will call checkGrammarNumericLiteral during expression checking. Similarly for template literals. So the check might be redundant for a full check. I'll test and see.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just tested .. removing the check from here does not fail any test 😕. I do think it ends up being called through other paths.

@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,484k (± 0.00%) 295,498k (± 0.01%) ~ 295,465k 295,539k p=0.298 n=6
Parse Time 3.19s (± 0.24%) 3.19s (± 0.71%) ~ 3.17s 3.23s p=0.564 n=6
Bind Time 0.99s (± 0.52%) 1.00s (± 0.84%) ~ 0.99s 1.01s p=0.923 n=6
Check Time 9.68s (± 0.27%) 9.69s (± 0.36%) ~ 9.63s 9.73s p=0.747 n=6
Emit Time 8.37s (± 0.14%) 8.37s (± 0.43%) ~ 8.32s 8.42s p=0.627 n=6
Total Time 22.23s (± 0.14%) 22.23s (± 0.20%) ~ 22.19s 22.31s p=0.747 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 192,583k (± 0.78%) 192,046k (± 0.08%) ~ 191,913k 192,315k p=0.936 n=6
Parse Time 1.66s (± 0.99%) 1.65s (± 0.89%) ~ 1.63s 1.67s p=0.871 n=6
Bind Time 0.88s (± 0.59%) 0.88s (± 0.72%) ~ 0.87s 0.89s p=0.386 n=6
Check Time 11.21s (± 0.74%) 11.27s (± 0.89%) ~ 11.11s 11.36s p=0.298 n=6
Emit Time 3.14s (± 0.87%) 3.14s (± 0.47%) ~ 3.11s 3.15s p=1.000 n=6
Total Time 16.89s (± 0.53%) 16.93s (± 0.72%) ~ 16.74s 17.05s p=0.336 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,443k (± 0.01%) 347,451k (± 0.00%) ~ 347,431k 347,472k p=0.423 n=6
Parse Time 3.69s (± 1.58%) 3.67s (± 1.51%) ~ 3.57s 3.73s p=0.574 n=6
Bind Time 1.39s (± 1.18%) 1.38s (± 1.00%) ~ 1.35s 1.39s p=0.341 n=6
Check Time 10.25s (± 0.21%) 10.24s (± 0.50%) ~ 10.16s 10.30s p=1.000 n=6
Emit Time 6.02s (± 0.54%) 6.02s (± 0.47%) ~ 5.99s 6.07s p=0.686 n=6
Total Time 21.34s (± 0.29%) 21.31s (± 0.41%) ~ 21.18s 21.42s p=0.630 n=6
TFS - node (v18.15.0, x64)
Memory used 302,734k (± 0.01%) 302,751k (± 0.01%) ~ 302,709k 302,800k p=0.378 n=6
Parse Time 2.40s (± 1.10%) 2.40s (± 1.38%) ~ 2.36s 2.43s p=0.936 n=6
Bind Time 1.19s (± 0.43%) 1.22s (± 0.80%) +0.03s (+ 2.37%) 1.21s 1.23s p=0.004 n=6
Check Time 7.46s (± 0.36%) 7.48s (± 0.40%) ~ 7.44s 7.53s p=0.805 n=6
Emit Time 4.27s (± 0.76%) 4.28s (± 0.60%) ~ 4.25s 4.32s p=0.570 n=6
Total Time 15.32s (± 0.25%) 15.38s (± 0.37%) ~ 15.32s 15.48s p=0.072 n=6
material-ui - node (v18.15.0, x64)
Memory used 509,981k (± 0.01%) 509,965k (± 0.01%) ~ 509,923k 510,005k p=0.575 n=6
Parse Time 3.92s (± 0.19%) 3.93s (± 0.37%) ~ 3.91s 3.95s p=0.117 n=6
Bind Time 1.46s (± 0.67%) 1.46s (± 0.71%) ~ 1.45s 1.48s p=0.452 n=6
Check Time 25.31s (± 0.17%) 25.41s (± 0.32%) ~ 25.30s 25.48s p=0.052 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 30.69s (± 0.14%) 30.80s (± 0.27%) +0.11s (+ 0.36%) 30.68s 30.88s p=0.029 n=6
mui-docs - node (v18.15.0, x64)
Memory used 1,737,822k (± 0.00%) 1,737,828k (± 0.00%) ~ 1,737,795k 1,737,850k p=0.575 n=6
Parse Time 7.78s (± 0.25%) 7.79s (± 0.70%) ~ 7.71s 7.86s p=0.687 n=6
Bind Time 2.79s (± 0.32%) 2.79s (± 0.74%) ~ 2.76s 2.81s p=0.367 n=6
Check Time 66.71s (± 0.42%) 66.60s (± 0.15%) ~ 66.51s 66.77s p=0.378 n=6
Emit Time 0.16s (± 3.29%) 0.16s (± 2.58%) ~ 0.15s 0.16s p=0.595 n=6
Total Time 77.44s (± 0.35%) 77.34s (± 0.14%) ~ 77.17s 77.48s p=0.378 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,392,034k (± 0.03%) 2,392,685k (± 0.03%) ~ 2,391,537k 2,393,515k p=0.128 n=6
Parse Time 6.06s (± 0.50%) 6.07s (± 0.66%) ~ 6.01s 6.12s p=0.574 n=6
Bind Time 2.26s (± 1.03%) 2.25s (± 0.92%) ~ 2.23s 2.29s p=0.413 n=6
Check Time 39.67s (± 0.50%) 39.53s (± 0.34%) ~ 39.43s 39.78s p=0.298 n=6
Emit Time 3.15s (± 1.09%) 3.18s (± 1.35%) ~ 3.14s 3.26s p=0.297 n=6
Total Time 51.15s (± 0.35%) 51.04s (± 0.25%) ~ 50.91s 51.27s p=0.378 n=6
self-compiler - node (v18.15.0, x64)
Memory used 415,053k (± 0.01%) 415,056k (± 0.01%) ~ 415,014k 415,119k p=0.873 n=6
Parse Time 4.17s (± 0.65%) 4.11s (± 0.65%) -0.06s (- 1.32%) 4.08s 4.14s p=0.020 n=6
Bind Time 1.58s (± 0.96%) 1.59s (± 1.66%) ~ 1.55s 1.62s p=0.808 n=6
Check Time 22.38s (± 0.38%) 22.29s (± 0.43%) ~ 22.16s 22.42s p=0.092 n=6
Emit Time 1.68s (± 1.78%) 1.68s (± 1.99%) ~ 1.64s 1.72s p=1.000 n=6
Total Time 29.81s (± 0.28%) 29.67s (± 0.41%) ~ 29.51s 29.85s p=0.054 n=6
vscode - node (v18.15.0, x64)
Memory used 2,892,649k (± 0.00%) 2,892,623k (± 0.00%) ~ 2,892,494k 2,892,679k p=0.575 n=6
Parse Time 12.87s (± 0.33%) 12.86s (± 0.25%) ~ 12.82s 12.91s p=0.570 n=6
Bind Time 4.12s (± 1.17%) 4.11s (± 0.33%) ~ 4.09s 4.13s p=0.742 n=6
Check Time 71.33s (± 0.43%) 71.15s (± 0.45%) ~ 70.70s 71.45s p=0.422 n=6
Emit Time 19.99s (± 7.78%) 19.20s (± 0.23%) ~ 19.13s 19.27s p=0.108 n=6
Total Time 108.30s (± 1.68%) 107.31s (± 0.32%) ~ 106.84s 107.69s p=0.128 n=6
webpack - node (v18.15.0, x64)
Memory used 408,368k (± 0.01%) 408,443k (± 0.02%) ~ 408,385k 408,618k p=0.128 n=6
Parse Time 3.88s (± 0.47%) 3.89s (± 0.48%) ~ 3.87s 3.92s p=0.869 n=6
Bind Time 1.69s (± 0.99%) 1.69s (± 1.06%) ~ 1.67s 1.71s p=1.000 n=6
Check Time 16.71s (± 0.34%) 16.77s (± 0.35%) ~ 16.69s 16.86s p=0.230 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 22.29s (± 0.25%) 22.34s (± 0.23%) ~ 22.27s 22.42s p=0.170 n=6
xstate - node (v18.15.0, x64)
Memory used 513,092k (± 0.02%) 513,089k (± 0.01%) ~ 512,988k 513,124k p=0.630 n=6
Parse Time 3.28s (± 0.31%) 3.28s (± 0.33%) ~ 3.27s 3.30s p=0.863 n=6
Bind Time 1.57s (± 0.62%) 1.57s (± 0.40%) ~ 1.56s 1.58s p=0.733 n=6
Check Time 2.85s (± 1.17%) 2.85s (± 0.68%) ~ 2.83s 2.88s p=0.570 n=6
Emit Time 0.07s (± 5.69%) 0.07s (± 0.00%) ~ 0.07s 0.07s p=0.405 n=6
Total Time 7.77s (± 0.46%) 7.77s (± 0.29%) ~ 7.75s 7.80s p=0.517 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

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,374ms (± 0.90%) 2,371ms (± 0.35%) ~ 2,361ms 2,381ms p=1.000 n=6
Req 2 - geterr 5,612ms (± 0.39%) 5,635ms (± 0.41%) ~ 5,604ms 5,667ms p=0.173 n=6
Req 3 - references 317ms (± 0.24%) 318ms (± 0.33%) ~ 316ms 319ms p=0.611 n=6
Req 4 - navto 273ms (± 0.15%) 272ms (± 0.00%) -1ms (- 0.43%) 272ms 272ms p=0.002 n=6
Req 5 - completionInfo count 1,357 (± 0.00%) 1,357 (± 0.00%) ~ 1,357 1,357 p=1.000 n=6
Req 5 - completionInfo 87ms (± 3.74%) 87ms (± 0.47%) -0ms (- 0.19%) 87ms 88ms p=0.047 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,504ms (± 0.42%) 2,505ms (± 0.44%) ~ 2,493ms 2,522ms p=0.872 n=6
Req 2 - geterr 4,145ms (± 0.25%) 4,134ms (± 0.13%) -12ms (- 0.28%) 4,129ms 4,141ms p=0.030 n=6
Req 3 - references 333ms (± 0.27%) 333ms (± 0.45%) ~ 332ms 336ms p=0.933 n=6
Req 4 - navto 298ms (± 0.14%) 296ms (± 0.93%) ~ 293ms 298ms p=0.054 n=6
Req 5 - completionInfo count 1,519 (± 0.00%) 1,519 (± 0.00%) ~ 1,519 1,519 p=1.000 n=6
Req 5 - completionInfo 73ms (± 0.56%) 73ms (± 0.56%) ~ 72ms 73ms p=0.218 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,635ms (± 0.20%) 2,632ms (± 0.26%) ~ 2,619ms 2,638ms p=0.575 n=6
Req 2 - geterr 1,740ms (± 2.59%) 1,744ms (± 2.53%) ~ 1,686ms 1,796ms p=0.936 n=6
Req 3 - references 115ms (±10.96%) 126ms (± 1.64%) ~ 122ms 128ms p=0.332 n=6
Req 4 - navto 370ms (± 2.39%) 368ms (± 0.64%) ~ 366ms 371ms p=1.000 n=6
Req 5 - completionInfo count 2,079 (± 0.00%) 2,079 (± 0.00%) ~ 2,079 2,079 p=1.000 n=6
Req 5 - completionInfo 307ms (± 1.64%) 306ms (± 2.03%) ~ 301ms 316ms p=0.872 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstateTSServer - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v18.15.0, x64)
Execution time 153.27ms (± 0.19%) 153.29ms (± 0.19%) ~ 152.20ms 158.35ms p=0.376 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 226.55ms (± 0.14%) 226.41ms (± 0.18%) -0.14ms (- 0.06%) 224.79ms 231.70ms p=0.000 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 221.80ms (± 0.16%) 221.81ms (± 0.16%) ~ 220.48ms 225.00ms p=0.929 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 221.48ms (± 0.17%) 221.28ms (± 0.15%) -0.19ms (- 0.09%) 219.98ms 225.87ms p=0.000 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

Just a philosophy question here: utilities.ts is a now 10,000 line long file of what is essentially uncategorized helper functions. Since we refer to it as "the expression evaluator", does that imply it's standalone enough that it should warrant its' own file, rather than getting tossed in alongside the other uncategorized helper functions?

@DanielRosenwasser
Copy link
Member

does that imply it's standalone enough that it should warrant its' own file, rather than getting tossed in alongside the other uncategorized helper functions?

Given how small it is and how often new files get created, I think it's probably fine in utilities.ts - at least for now.

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

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

Seems like a very simple change.

@weswigham weswigham merged commit fd388f7 into microsoft:main Mar 27, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants