Skip to content

Avoid hashing keys in active mapper instantiation caches - #64871

Open
Jake Bailey (jakebailey) wants to merge 1 commit into
microsoft:mainfrom
jakebailey:perf/mapper-cache-without-hashing
Open

Jake Bailey (jakebailey) wants to merge 1 commit into
microsoft:mainfrom
jakebailey:perf/mapper-cache-without-hashing

Conversation

@jakebailey

Copy link
Copy Markdown
Member

Every instantiation under an active mapper built and hashed a 128-bit key before probing the mapper's cache, even when the mapper had just been pushed and its cache was necessarily empty. Most keys carry no alias, so the type ID alone identifies the entry.

Measured with --checkers 4 (n=8):

                      │ before.txt │            after.txt             │
                      │   sec/op   │   sec/op    vs base              │
    Tsc/bluesky         2.756 ± 3%   2.742 ± 3%       ~ (p=0.366 n=8)
    Tsc/sentry          11.20 ± 3%   11.19 ± 4%       ~ (p=0.742 n=8)
    Tsc/t3code-server   10.84 ± 3%   10.72 ± 2%  -1.10% (p=0.038 n=8)
    geomean             6.942        6.902       -0.58%

                      │  before.txt  │             after.txt              │
                      │    rss-B     │    rss-B      vs base              │
    Tsc/bluesky         1.190Gi ± 1%   1.182Gi ± 3%       ~ (p=0.798 n=8)
    Tsc/sentry          3.438Gi ± 7%   3.518Gi ± 6%       ~ (p=0.645 n=8)
    Tsc/t3code-server   2.852Gi ± 2%   2.879Gi ± 3%       ~ (p=0.721 n=8)
    geomean             2.268Gi        2.287Gi       +0.86%

                      │  before.txt  │             after.txt              │
                      │    heap-B    │    heap-B     vs base              │
    Tsc/bluesky         934.9Mi ± 0%   934.8Mi ± 0%       ~ (p=0.959 n=8)
    Tsc/sentry          2.607Gi ± 0%   2.609Gi ± 0%       ~ (p=0.382 n=8)
    Tsc/t3code-server   2.303Gi ± 0%   2.302Gi ± 0%       ~ (p=0.083 n=8)
    geomean             1.763Gi        1.763Gi       -0.00%

Every instantiation under an active mapper built and hashed a 128-bit
key before probing the mapper's cache, even when the mapper had just
been pushed and its cache was necessarily empty. Most keys carry no
alias, so the type ID alone identifies the entry.

Measured with --checkers 4 (n=8):

                      │ before.txt │            after.txt             │
                      │   sec/op   │   sec/op    vs base              │
    Tsc/bluesky         2.756 ± 3%   2.742 ± 3%       ~ (p=0.366 n=8)
    Tsc/sentry          11.20 ± 3%   11.19 ± 4%       ~ (p=0.742 n=8)
    Tsc/t3code-server   10.84 ± 3%   10.72 ± 2%  -1.10% (p=0.038 n=8)
    geomean             6.942        6.902       -0.58%

                      │  before.txt  │             after.txt              │
                      │    rss-B     │    rss-B      vs base              │
    Tsc/bluesky         1.190Gi ± 1%   1.182Gi ± 3%       ~ (p=0.798 n=8)
    Tsc/sentry          3.438Gi ± 7%   3.518Gi ± 6%       ~ (p=0.645 n=8)
    Tsc/t3code-server   2.852Gi ± 2%   2.879Gi ± 3%       ~ (p=0.721 n=8)
    geomean             2.268Gi        2.287Gi       +0.86%

                      │  before.txt  │             after.txt              │
                      │    heap-B    │    heap-B     vs base              │
    Tsc/bluesky         934.9Mi ± 0%   934.8Mi ± 0%       ~ (p=0.959 n=8)
    Tsc/sentry          2.607Gi ± 0%   2.609Gi ± 0%       ~ (p=0.382 n=8)
    Tsc/t3code-server   2.303Gi ± 0%   2.302Gi ± 0%       ~ (p=0.083 n=8)
    geomean             1.763Gi        1.763Gi       -0.00%
Copilot AI balanced review requested due to automatic review settings October 19, 2026 17:40
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 19, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused optimization preserves cache behavior, with no blocking issues identified.

No open issues 🎉

What changed in this PR

Optimizes the compiler’s active mapper instantiation cache to reduce unnecessary key hashing.

Changes:

  • Skips cache lookup and key construction for newly pushed mappers.
  • Uses type IDs directly for alias-free keys, retaining hashing for aliased types.
File Description
tsc/​internal/​checker/​checker.go Streamlines mapper cache lookups and adds optimized key generation.

Review effort: Balanced

@jakebailey

Copy link
Copy Markdown
Member Author

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

@typescript-automation

typescript-automation Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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

Command Status Results
perf test this faster ✅ Started 👀 Results

@typescript-automation

Copy link
Copy Markdown
Contributor

Jake Bailey (@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
Compiler-Unions - native
Errors 41 41 ~ ~ ~ p=1.000 n=12
Symbols 115,276 115,276 ~ ~ ~ p=1.000 n=12
Types 79,613 79,613 ~ ~ ~ p=1.000 n=12
Memory Used 113,521k (± 0.07%) 113,532k (± 0.07%) ~ 113,391k 113,772k p=0.767 n=12
Memory Allocs 2,212,535 (± 0.00%) 2,212,560 (± 0.00%) ~ 2,212,245 2,212,832 p=0.787 n=12
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Parse Time 0.039s (± 3.96%) 0.040s (± 2.84%) ~ 0.036s 0.043s p=0.181 n=12
Bind Time 0.013s (± 9.04%) 0.014s (± 9.81%) ~ 0.011s 0.018s p=0.407 n=12
Check Time 0.471s (± 0.93%) 0.468s (± 0.67%) ~ 0.460s 0.477s p=0.297 n=12
Emit Time 0.267s (± 2.35%) 0.268s (± 1.89%) ~ 0.256s 0.282s p=0.560 n=12
Total Time 0.796s (± 1.16%) 0.797s (± 0.73%) ~ 0.783s 0.815s p=0.579 n=12
angular-1 - native
Errors 3 3 ~ ~ ~ p=1.000 n=12
Symbols 847,336 (± 0.09%) 847,078 (± 0.06%) ~ 846,015 848,350 p=0.514 n=12
Types 247,033 (± 0.00%) 247,032 (± 0.00%) ~ 247,030 247,041 p=0.197 n=12
Memory Used 596,504k (± 0.02%) 596,432k (± 0.02%) ~ 596,168k 596,823k p=0.514 n=12
Memory Allocs 13,141,629 (± 0.04%) 13,141,423 (± 0.04%) ~ 13,135,332 13,166,204 p=0.378 n=12
Config Time 0.017s (± 1.45%) 0.017s (± 1.70%) ~ 0.016s 0.017s p=1.000 n=12
Parse Time 0.226s (± 2.72%) 0.224s (± 3.46%) ~ 0.208s 0.241s p=0.809 n=12
Bind Time 0.073s (±13.84%) 0.081s (±17.09%) ~ 0.058s 0.113s p=0.619 n=12
Check Time 0s 0s ~ ~ ~ p=1.000 n=12
Emit Time 1.574s (± 1.50%) 1.549s (± 1.38%) ~ 1.490s 1.590s p=0.124 n=12
Total Time 1.911s (± 1.50%) 1.886s (± 1.22%) ~ 1.817s 1.937s p=0.272 n=12
mui-docs - native
Errors 11,405 11,405 ~ ~ ~ p=1.000 n=12
Symbols 4,331,983 4,331,983 ~ ~ ~ p=1.000 n=12
Types 1,370,520 1,370,520 ~ ~ ~ p=1.000 n=12
Memory Used 2,625,370k (± 0.06%) 2,625,610k (± 0.07%) ~ 2,622,009k 2,631,093k p=0.671 n=12
Memory Allocs 27,710,899 (± 0.07%) 27,707,576 (± 0.09%) ~ 27,659,623 27,787,079 p=0.630 n=12
Config Time 0.020s (± 0.90%) 0.020s ~ ~ ~ p=1.000 n=12
Parse Time 0.567s (± 2.69%) 0.587s (± 2.37%) ~ 0.557s 0.621s p=0.080 n=12
Bind Time 0.003s (±26.03%) 0.003s (±11.61%) ~ 0.002s 0.003s p=0.680 n=12
Check Time 8.594s (± 0.21%) 8.593s (± 0.63%) ~ 8.473s 8.774s p=0.192 n=12
Emit Time 0.700s (± 9.88%) 0.650s (±12.93%) ~ 0.497s 0.785s p=0.164 n=12
Total Time 10.815s (± 0.66%) 10.758s (± 0.79%) ~ 10.509s 10.909s p=0.139 n=12
strada-build-src - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 1,388,680 1,388,680 ~ ~ ~ p=1.000 n=12
Types 441,862 441,862 ~ ~ ~ p=1.000 n=12
Memory Used 1,314,690k (± 0.59%) 1,311,651k (± 0.52%) ~ 1,300,979k 1,336,741k p=0.410 n=12
Memory Allocs 78,296,066 (± 0.05%) 78,228,132 (± 0.11%) ~ 77,874,740 78,356,818 p=0.410 n=12
Config Time 0.004s (± 8.27%) 0.004s (± 6.39%) ~ 0.003s 0.004s p=1.000 n=12
Parse Time 0.252s (± 1.93%) 0.252s (± 1.88%) ~ 0.241s 0.264s p=0.619 n=12
Bind Time 0.000s (±217.90%) 0.000s ~ ~ ~ p=1.000 n=12
Check Time 1.668s (± 0.48%) 1.660s (± 0.46%) ~ 1.643s 1.689s p=0.086 n=12
Emit Time 0.310s (± 5.03%) 0.297s (± 5.15%) ~ 0.266s 0.339s p=0.340 n=12
Total Time 19.806s (± 0.52%) 19.669s (± 0.73%) ~ 19.291s 19.938s p=0.370 n=12
strada-compiler - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 334,953 334,953 ~ ~ ~ p=1.000 n=12
Types 197,616 197,616 ~ ~ ~ p=1.000 n=12
Memory Used 247,562k (± 0.02%) 247,533k (± 0.02%) ~ 247,413k 247,698k p=0.514 n=12
Memory Allocs 4,329,862 (± 0.01%) 4,329,842 (± 0.01%) ~ 4,328,943 4,330,990 p=0.875 n=12
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=12
Parse Time 0.114s (± 5.62%) 0.115s (± 5.14%) ~ 0.104s 0.130s p=0.966 n=12
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Check Time 0.961s (± 0.64%) 0.958s (± 0.70%) ~ 0.944s 0.976s p=0.486 n=12
Emit Time 0.146s (± 6.54%) 0.151s (± 5.09%) ~ 0.131s 0.173s p=0.504 n=12
Total Time 1.279s (± 0.74%) 1.278s (± 0.77%) ~ 1.249s 1.299s p=0.766 n=12
ts-pre-modules - native
Errors 87 87 ~ ~ ~ p=1.000 n=12
Symbols 303,834 303,834 ~ ~ ~ p=1.000 n=12
Types 181,663 181,663 ~ ~ ~ p=1.000 n=12
Memory Used 215,232k (± 0.02%) 215,242k (± 0.02%) ~ 215,098k 215,370k p=0.671 n=12
Memory Allocs 1,401,433 (± 0.01%) 1,401,694 (± 0.02%) ~ 1,401,241 1,402,346 p=0.078 n=12
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Parse Time 0.095s (± 3.85%) 0.097s (± 3.54%) ~ 0.089s 0.106s p=0.354 n=12
Bind Time 0.041s (±11.21%) 0.040s (± 8.26%) ~ 0.033s 0.051s p=0.809 n=12
Check Time 0.741s (± 0.69%) 0.740s (± 0.87%) ~ 0.727s 0.757s p=0.639 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 0.892s (± 0.44%) 0.892s (± 0.97%) ~ 0.873s 0.912s p=0.680 n=12
vscode - native
Errors 396 396 ~ ~ ~ p=1.000 n=12
Symbols 12,386,876 12,386,876 ~ ~ ~ p=1.000 n=12
Types 4,049,733 4,049,733 ~ ~ ~ p=1.000 n=12
Memory Used 5,821,839k (± 0.02%) 5,821,463k (± 0.02%) ~ 5,819,511k 5,824,730k p=0.478 n=12
Memory Allocs 59,185,798 (± 0.01%) 59,190,729 (± 0.02%) ~ 59,178,341 59,237,100 p=0.799 n=12
Config Time 0.062s (± 0.39%) 0.062s (± 0.43%) ~ 0.061s 0.063s p=0.627 n=12
Parse Time 1.448s (± 1.91%) 1.466s (± 2.86%) ~ 1.386s 1.626s p=0.630 n=12
Bind Time 0.579s (±13.74%) 0.539s (±13.21%) ~ 0.402s 0.707s p=0.248 n=12
Check Time 13.050s (± 0.94%) 13.078s (± 1.01%) ~ 12.854s 13.398s p=0.977 n=12
Emit Time 4.850s (± 7.19%) 4.770s (± 7.52%) ~ 3.801s 5.406s p=0.799 n=12
Total Time 20.067s (± 1.37%) 19.994s (± 1.40%) ~ 19.220s 20.532s p=0.671 n=12
webpack - native
Errors 598 598 ~ ~ ~ p=1.000 n=12
Symbols 1,398,302 1,398,302 ~ ~ ~ p=1.000 n=12
Types 670,900 670,900 ~ ~ ~ p=1.000 n=12
Memory Used 885,687k (± 0.02%) 885,754k (± 0.02%) ~ 885,303k 886,198k p=0.671 n=12
Memory Allocs 6,926,710 (± 0.01%) 6,927,880 (± 0.03%) ~ 6,923,495 6,936,369 p=0.291 n=12
Config Time 0.008s (± 4.27%) 0.007s (± 4.37%) ~ 0.007s 0.008s p=0.684 n=12
Parse Time 0.250s (± 2.26%) 0.251s (± 3.83%) ~ 0.226s 0.276s p=0.832 n=12
Bind Time 0.062s (± 8.13%) 0.063s (±11.52%) ~ 0.055s 0.087s p=0.414 n=12
Check Time 2.466s (± 0.45%) 2.461s (± 0.39%) ~ 2.440s 2.501s p=0.103 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 2.818s (± 0.34%) 2.813s (± 0.51%) ~ 2.778s 2.854s p=0.504 n=12
xstate-main - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 1,060,810 1,060,810 ~ ~ ~ p=1.000 n=12
Types 389,671 389,671 ~ ~ ~ p=1.000 n=12
Memory Used 471,926k (± 0.03%) 471,848k (± 0.02%) ~ 471,638k 472,281k p=0.347 n=12
Memory Allocs 4,222,579 (± 0.12%) 4,220,463 (± 0.08%) ~ 4,212,645 4,232,279 p=0.843 n=12
Config Time 0.003s (± 6.23%) 0.003s (± 6.23%) ~ 0.002s 0.003s p=1.000 n=12
Parse Time 0.137s (± 3.20%) 0.136s (± 3.56%) ~ 0.123s 0.146s p=0.744 n=12
Bind Time 0.041s (±15.18%) 0.040s (±14.56%) ~ 0.034s 0.066s p=0.896 n=12
Check Time 1.095s (± 1.17%) 1.072s (± 0.90%) -0.023s (- 2.10%) 1.054s 1.099s p=0.006 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 1.283s (± 1.05%) 1.258s (± 0.92%) -0.026s (- 2.00%) 1.238s 1.287s p=0.005 n=12
System info unknown
Hosts
  • native
Scenarios
  • Compiler-Unions - native
  • angular-1 - native
  • mui-docs - native
  • strada-build-src - native
  • strada-compiler - native
  • ts-pre-modules - native
  • vscode - native
  • webpack - native
  • xstate-main - native
Benchmark Name Iterations
Current pr 12
Baseline baseline 12

Developer Information:

Download Benchmarks

This branch has not been deployed

No deployments
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

Status: Not started

Development

Successfully merging this pull request may close these issues.

2 participants