Skip to content

Inline the common fast-fail of isSimpleTypeRelatedTo - #65038

Open
Jake Bailey (jakebailey) wants to merge 1 commit into
microsoft:mainfrom
jakebailey:perf/relation-helpers
Open

Jake Bailey (jakebailey) wants to merge 1 commit into
microsoft:mainfrom
jakebailey:perf/relation-helpers

Conversation

@jakebailey

@jakebailey Jake Bailey (jakebailey) commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

isSimpleTypeRelatedTo is called up to twice for nearly every relation check, and in the overwhelmingly common case (relating two structured or instantiable types where the target is not a union) it walks a long list of primitive flag tests only to return false. The function was far too large to inline, so each of those checks also paid for a call.

Split it into a small wrapper that fits the inlining budget and rejects that case directly, and a worker holding the full logic. The worker additionally short-circuits two cases whose outcome is already decided by a couple of flag tests: two enum members of the same kind, and two structured or instantiable types (where only the unknown-like union check can apply). Results are unchanged.

Thanks Steven (@teamchong) for finding this!

isSimpleTypeRelatedTo is called up to twice for nearly every relation
check, and in the overwhelmingly common case (relating two structured
or instantiable types where the target is not a union) it walks a long
list of primitive flag tests only to return false. The function was far
too large to inline, so each of those checks also paid for a call.

Split it into a small wrapper that fits the inlining budget and rejects
that case directly, and a worker holding the full logic. The worker
additionally short-circuits two cases whose outcome is already decided
by a couple of flag tests: two enum members of the same kind, and two
structured or instantiable types (where only the unknown-like union
check can apply). Results are unchanged.

Co-authored-by: Steven Chong <25894545+teamchong@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 29, 2026 21:26
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 29, 2026
@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 29, 2026
@jakebailey

Copy link
Copy Markdown
Member Author

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

@typescript-automation

typescript-automation Bot commented Oct 29, 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

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

No active review issues were identified in the type-relation fast-path refactor.

No open issues 🎉

What changed in this PR

Optimizes the native compiler’s type-relation checks by moving the common fast-fail path into a small, inlineable wrapper, while preserving the existing relation logic.

Changes:

  • Splits isSimpleTypeRelatedTo into a wrapper and a worker.
  • Adds early exits for matching-kind enum members and structured or instantiable types.
File Description
tsc/​internal/​checker/​relater.go Adds fast paths to reduce function-call overhead and unnecessary primitive flag checks.

Review effort: Balanced

@jakebailey Jake Bailey (jakebailey) added the Domain: Performance Reports of unusually slow behavior label Oct 29, 2026
@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=20
Symbols 88,466 88,466 ~ ~ ~ p=1.000 n=20
Types 79,607 79,607 ~ ~ ~ p=1.000 n=20
Memory Used 104,178k (± 0.03%) 104,136k (± 0.02%) ~ 104,045k 104,218k p=0.062 n=20
Memory Allocs 1,263,837 (± 0.01%) 1,263,922 (± 0.01%) ~ 1,263,481 1,264,509 p=0.383 n=20
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Parse Time 0.023s (± 2.84%) 0.023s (± 2.66%) ~ 0.021s 0.026s p=0.268 n=20
Bind Time 0.009s (± 4.57%) 0.009s (± 4.07%) ~ 0.008s 0.011s p=0.232 n=20
Check Time 0.218s (± 0.57%) 0.209s (± 0.76%) 🟩-0.009s (- 4.04%) 0.204s 0.216s p=0.000 n=20
Emit Time 0.144s (± 0.70%) 0.141s (± 1.02%) -0.002s (- 1.57%) 0.135s 0.145s p=0.025 n=20
Total Time 0.397s (± 0.51%) 0.386s (± 0.39%) -0.010s (- 2.62%) 0.380s 0.392s p=0.000 n=20
angular-1 - native
Errors 3 3 ~ ~ ~ p=1.000 n=20
Symbols 586,500 (± 0.02%) 586,501 (± 0.02%) ~ 586,106 586,827 p=0.963 n=20
Types 241,688 (± 0.00%) 241,687 (± 0.00%) ~ 241,683 241,697 p=0.169 n=20
Memory Used 517,917k (± 0.02%) 517,936k (± 0.02%) ~ 517,643k 518,360k p=0.482 n=20
Memory Allocs 7,798,729 (± 0.11%) 7,804,289 (± 0.12%) ~ 7,785,888 7,851,277 p=0.242 n=20
Config Time 0.009s 0.009s ~ ~ ~ p=1.000 n=20
Parse Time 0.126s (± 2.79%) 0.128s (± 2.52%) ~ 0.116s 0.142s p=0.371 n=20
Bind Time 0.046s (± 9.84%) 0.047s (±11.03%) ~ 0.038s 0.068s p=0.787 n=20
Check Time 0s 0s ~ ~ ~ p=1.000 n=20
Emit Time 0.854s (± 1.08%) 0.853s (± 1.09%) ~ 0.824s 0.881s p=0.984 n=20
Total Time 1.045s (± 1.25%) 1.049s (± 1.35%) ~ 1.010s 1.092s p=0.825 n=20
arktype - native
Errors 0 0 ~ ~ ~ p=1.000 n=20
Symbols 685,920 685,920 ~ ~ ~ p=1.000 n=20
Types 939,467 939,467 ~ ~ ~ p=1.000 n=20
Memory Used 497,271k (± 0.01%) 497,292k (± 0.01%) ~ 497,131k 497,508k p=0.825 n=20
Memory Allocs 12,109,421 (± 0.02%) 12,108,253 (± 0.01%) ~ 12,104,526 12,117,478 p=0.565 n=20
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=20
Parse Time 0.043s (± 3.29%) 0.043s (± 3.26%) ~ 0.038s 0.049s p=0.866 n=20
Bind Time 0.014s (± 9.96%) 0.013s (± 7.39%) ~ 0.012s 0.020s p=0.901 n=20
Check Time 1.011s (± 1.35%) 1.009s (± 1.54%) ~ 0.968s 1.075s p=0.899 n=20
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Total Time 1.099s (± 1.26%) 1.095s (± 1.43%) ~ 1.052s 1.166s p=0.616 n=20
class-transformer - native
Errors 0 0 ~ ~ ~ p=1.000 n=20
Symbols 45,376 45,376 ~ ~ ~ p=1.000 n=20
Types 7,573 7,573 ~ ~ ~ p=1.000 n=20
Memory Used 27,838k (± 0.03%) 27,834k (± 0.02%) ~ 27,817k 27,847k p=0.783 n=20
Memory Allocs 248,687 (± 0.08%) 248,812 (± 0.06%) ~ 248,138 249,353 p=0.221 n=20
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Parse Time 0.011s (± 3.83%) 0.011s (± 4.28%) ~ 0.009s 0.014s p=0.284 n=20
Bind Time 0.004s (±10.85%) 0.003s (±10.34%) ~ 0.003s 0.006s p=0.582 n=20
Check Time 0.008s (± 7.97%) 0.008s (± 5.79%) ~ 0.007s 0.011s p=0.810 n=20
Emit Time 0.009s (± 7.13%) 0.009s (± 4.50%) ~ 0.007s 0.010s p=0.802 n=20
Total Time 0.032s (± 2.78%) 0.033s (± 2.11%) ~ 0.030s 0.036s p=0.178 n=20
effect - native
Errors 12 12 ~ ~ ~ p=1.000 n=20
Symbols 1,235,115 1,235,115 ~ ~ ~ p=1.000 n=20
Types 894,113 894,113 ~ ~ ~ p=1.000 n=20
Memory Used 940,543k (± 0.02%) 940,604k (± 0.02%) ~ 939,888k 941,349k p=0.738 n=20
Memory Allocs 12,673,963 (± 0.03%) 12,672,100 (± 0.03%) ~ 12,662,403 12,695,584 p=0.547 n=20
Config Time 0.002s 0.002s ~ ~ ~ p=1.000 n=20
Parse Time 0.150s (± 1.87%) 0.147s (± 1.57%) ~ 0.136s 0.157s p=0.086 n=20
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Check Time 0.955s (± 4.04%) 0.946s (± 1.52%) ~ 0.906s 1.018s p=0.723 n=20
Emit Time 0.519s (± 2.33%) 0.512s (± 2.45%) ~ 0.471s 0.556s p=0.433 n=20
Total Time 1.721s (± 2.59%) 1.701s (± 1.26%) ~ 1.639s 1.793s p=0.878 n=20
mui-docs - native
Errors 11,405 11,405 ~ ~ ~ p=1.000 n=20
Symbols 3,784,019 3,784,019 ~ ~ ~ p=1.000 n=20
Types 1,355,974 1,355,974 ~ ~ ~ p=1.000 n=20
Memory Used 1,837,004k (± 0.07%) 1,836,561k (± 0.08%) ~ 1,830,969k 1,841,800k p=0.602 n=20
Memory Allocs 25,999,101 (± 0.08%) 25,972,164 (± 0.09%) -26,937 (- 0.10%) 25,920,150 26,118,889 p=0.023 n=20
Config Time 0.008s 0.008s ~ ~ ~ p=1.000 n=20
Parse Time 0.298s (± 1.15%) 0.303s (± 2.14%) ~ 0.283s 0.345s p=0.783 n=20
Bind Time 0.001s 0.001s ~ ~ ~ p=1.000 n=20
Check Time 3.075s (± 1.11%) 3.045s (± 0.53%) ~ 3.000s 3.117s p=0.189 n=20
Emit Time 0.238s (± 0.84%) 0.241s (± 1.28%) ~ 0.231s 0.257s p=0.111 n=20
Total Time 4.118s (± 0.91%) 4.087s (± 0.43%) ~ 4.039s 4.181s p=0.298 n=20
sentry - native
Errors 2 2 ~ ~ ~ p=1.000 n=20
Symbols 4,793,245 4,793,245 ~ ~ ~ p=1.000 n=20
Types 2,607,045 2,607,045 ~ ~ ~ p=1.000 n=20
Memory Used 2,880,745k (± 0.03%) 2,881,605k (± 0.04%) ~ 2,877,976k 2,887,596k p=0.478 n=20
Memory Allocs 75,267,525 (± 0.21%) 75,462,391 (± 0.37%) ~ 74,747,405 77,167,986 p=0.640 n=20
Config Time 0.026s (± 1.91%) 0.026s (± 1.50%) ~ 0.024s 0.027s p=0.238 n=20
Parse Time 0.490s (± 2.83%) 0.515s (± 5.53%) ~ 0.444s 0.667s p=0.507 n=20
Bind Time 0.174s (±10.13%) 0.174s (±12.01%) ~ 0.139s 0.297s p=0.597 n=20
Check Time 7.050s (± 0.87%) 6.939s (± 1.04%) -0.112s (- 1.58%) 6.639s 7.209s p=0.038 n=20
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Total Time 7.793s (± 0.77%) 7.704s (± 0.97%) ~ 7.429s 8.050s p=0.085 n=20
social-app - native
Errors 0 0 ~ ~ ~ p=1.000 n=20
Symbols 1,883,074 1,883,074 ~ ~ ~ p=1.000 n=20
Types 1,158,168 1,158,168 ~ ~ ~ p=1.000 n=20
Memory Used 972,513k (± 0.01%) 972,396k (± 0.01%) ~ 971,395k 972,833k p=0.337 n=20
Memory Allocs 13,579,418 (± 0.10%) 13,577,771 (± 0.16%) ~ 13,528,844 13,685,357 p=0.314 n=20
Config Time 0.008s (± 1.31%) 0.008s ~ ~ ~ p=1.000 n=20
Parse Time 0.163s (± 3.73%) 0.162s (± 2.70%) ~ 0.149s 0.184s p=0.835 n=20
Bind Time 0.048s (±10.17%) 0.049s (± 8.44%) ~ 0.042s 0.074s p=0.638 n=20
Check Time 1.602s (± 1.24%) 1.610s (± 1.22%) ~ 1.545s 1.719s p=0.763 n=20
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Total Time 1.840s (± 1.09%) 1.849s (± 1.11%) ~ 1.775s 1.968s p=0.713 n=20
strada-build-src - native
Errors 0 0 ~ ~ ~ p=1.000 n=20
Symbols 1,184,972 1,184,972 ~ ~ ~ p=1.000 n=20
Types 438,963 438,963 ~ ~ ~ p=1.000 n=20
Memory Used 1,167,220k (± 0.29%) 1,166,515k (± 0.27%) ~ 1,149,275k 1,184,342k p=0.779 n=20
Memory Allocs 47,675,090 (± 0.12%) 47,709,861 (± 0.10%) ~ 47,490,358 47,860,307 p=0.211 n=20
Config Time 0.002s (±18.96%) 0.002s (±14.66%) ~ 0.001s 0.003s p=0.552 n=20
Parse Time 0.140s (± 1.63%) 0.141s (± 2.09%) ~ 0.130s 0.160s p=0.825 n=20
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Check Time 0.818s (± 0.91%) 0.807s (± 0.70%) -0.011s (- 1.34%) 0.792s 0.839s p=0.014 n=20
Emit Time 0.142s (± 1.30%) 0.143s (± 1.65%) ~ 0.134s 0.156s p=0.845 n=20
Total Time 9.497s (± 0.84%) 9.399s (± 0.77%) -0.098s (- 1.03%) 9.189s 9.775s p=0.029 n=20
strada-compiler - native
Errors 0 0 ~ ~ ~ p=1.000 n=20
Symbols 263,511 263,511 ~ ~ ~ p=1.000 n=20
Types 196,116 196,116 ~ ~ ~ p=1.000 n=20
Memory Used 224,586k (± 0.02%) 224,609k (± 0.02%) ~ 224,473k 224,785k p=0.784 n=20
Memory Allocs 2,401,286 (± 0.01%) 2,401,668 (± 0.01%) ~ 2,400,440 2,403,467 p=0.133 n=20
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Parse Time 0.052s (± 3.13%) 0.049s (± 2.53%) 🟩-0.002s (- 4.45%) 0.046s 0.056s p=0.047 n=20
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Check Time 0.383s (± 1.15%) 0.375s (± 0.90%) -0.008s (- 2.14%) 0.366s 0.392s p=0.005 n=20
Emit Time 0.050s (± 5.63%) 0.049s (± 5.72%) ~ 0.042s 0.057s p=0.845 n=20
Total Time 0.513s (± 0.95%) 0.502s (± 0.83%) -0.011s (- 2.22%) 0.488s 0.525s p=0.001 n=20
t3code-server - native
Errors 0 0 ~ ~ ~ p=1.000 n=20
Symbols 4,350,661 4,350,661 ~ ~ ~ p=1.000 n=20
Types 3,040,644 3,040,644 ~ ~ ~ p=1.000 n=20
Memory Used 2,433,577k (± 0.02%) 2,433,934k (± 0.03%) ~ 2,431,832k 2,437,630k p=0.698 n=20
Memory Allocs 37,388,199 (± 0.10%) 37,386,574 (± 0.09%) ~ 37,293,712 37,595,825 p=0.883 n=20
Config Time 0.003s 0.003s ~ ~ ~ p=1.000 n=20
Parse Time 0.260s (± 2.52%) 0.257s (± 1.97%) ~ 0.240s 0.279s p=0.310 n=20
Bind Time 0.095s (±11.52%) 0.084s (± 6.30%) ~ 0.077s 0.118s p=0.103 n=20
Check Time 7.350s (± 0.75%) 7.295s (± 0.38%) ~ 7.189s 7.446s p=0.073 n=20
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Total Time 7.717s (± 0.69%) 7.651s (± 0.38%) -0.067s (- 0.86%) 7.523s 7.802s p=0.023 n=20
tanstack-router - native
Errors 1 1 ~ ~ ~ p=1.000 n=20
Symbols 571,756 571,756 ~ ~ ~ p=1.000 n=20
Types 397,689 397,689 ~ ~ ~ p=1.000 n=20
Memory Used 331,446k (± 0.02%) 331,433k (± 0.02%) ~ 331,163k 331,767k p=0.693 n=20
Memory Allocs 4,391,084 (± 0.14%) 4,388,352 (± 0.11%) ~ 4,378,066 4,412,473 p=0.445 n=20
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=20
Parse Time 0.039s (± 4.31%) 0.040s (± 3.41%) ~ 0.037s 0.045s p=0.462 n=20
Bind Time 0.015s (±10.25%) 0.012s (± 4.66%) 🟩-0.003s (-19.06%) 0.011s 0.015s p=0.001 n=20
Check Time 0.587s (± 0.57%) 0.584s (± 0.77%) ~ 0.572s 0.611s p=0.297 n=20
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Total Time 0.660s (± 0.68%) 0.657s (± 0.87%) ~ 0.642s 0.685s p=0.417 n=20
ts-pre-modules - native
Errors 87 87 ~ ~ ~ p=1.000 n=20
Symbols 231,616 231,616 ~ ~ ~ p=1.000 n=20
Types 181,195 181,195 ~ ~ ~ p=1.000 n=20
Memory Used 193,537k (± 0.01%) 193,529k (± 0.01%) ~ 193,457k 193,664k p=0.507 n=20
Memory Allocs 1,318,062 (± 0.01%) 1,318,404 (± 0.02%) +342 (+ 0.03%) 1,317,794 1,319,596 p=0.047 n=20
Config Time 0.000s 0.000s (±208.60%) ~ 0.000s 0.001s p=1.000 n=20
Parse Time 0.043s (± 2.84%) 0.044s (± 3.89%) ~ 0.038s 0.051s p=0.348 n=20
Bind Time 0.021s (± 4.98%) 0.021s (± 6.41%) ~ 0.017s 0.026s p=0.307 n=20
Check Time 0.295s (± 1.14%) 0.291s (± 0.78%) ~ 0.282s 0.299s p=0.062 n=20
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Total Time 0.366s (± 0.79%) 0.362s (± 0.73%) ~ 0.353s 0.372s p=0.077 n=20
vscode - native
Errors 11 11 ~ ~ ~ p=1.000 n=20
Symbols 7,504,980 7,504,980 ~ ~ ~ p=1.000 n=20
Types 4,419,852 4,419,852 ~ ~ ~ p=1.000 n=20
Memory Used 5,214,565k (± 0.02%) 5,215,729k (± 0.02%) ~ 5,211,984k 5,220,455k p=0.134 n=20
Memory Allocs 57,128,552 (± 0.03%) 57,124,782 (± 0.03%) ~ 57,096,179 57,191,377 p=0.820 n=20
Config Time 0.035s (± 1.88%) 0.035s (± 2.25%) ~ 0.032s 0.038s p=0.727 n=20
Parse Time 0.914s (± 2.15%) 0.938s (± 1.27%) ~ 0.897s 1.022s p=0.062 n=20
Bind Time 0.330s (± 7.59%) 0.312s (± 2.94%) ~ 0.294s 0.374s p=0.273 n=20
Check Time 7.514s (± 1.10%) 7.554s (± 1.15%) ~ 7.259s 7.797s p=0.534 n=20
Emit Time 2.853s (± 5.87%) 2.713s (± 2.10%) ~ 2.587s 3.155s p=0.635 n=20
Total Time 11.707s (± 1.96%) 11.610s (± 1.27%) ~ 11.174s 12.328s p=0.764 n=20
webpack - native
Errors 616 616 ~ ~ ~ p=1.000 n=20
Symbols 917,188 917,188 ~ ~ ~ p=1.000 n=20
Types 636,859 636,859 ~ ~ ~ p=1.000 n=20
Memory Used 693,547k (± 0.02%) 693,412k (± 0.02%) ~ 693,108k 693,877k p=0.098 n=20
Memory Allocs 6,499,249 (± 0.04%) 6,500,259 (± 0.04%) ~ 6,492,983 6,515,777 p=0.398 n=20
Config Time 0.004s 0.004s ~ ~ ~ p=1.000 n=20
Parse Time 0.147s (± 3.26%) 0.142s (± 3.65%) ~ 0.124s 0.167s p=0.064 n=20
Bind Time 0.043s (± 8.29%) 0.044s (± 9.50%) ~ 0.037s 0.070s p=0.835 n=20
Check Time 1.152s (± 0.91%) 1.148s (± 1.34%) ~ 1.114s 1.236s p=0.194 n=20
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Total Time 1.369s (± 1.03%) 1.361s (± 1.43%) ~ 1.316s 1.456s p=0.176 n=20
xstate-main - native
Errors 0 0 ~ ~ ~ p=1.000 n=20
Symbols 640,490 640,490 ~ ~ ~ p=1.000 n=20
Types 387,984 387,984 ~ ~ ~ p=1.000 n=20
Memory Used 350,939k (± 0.02%) 350,897k (± 0.02%) ~ 350,726k 351,521k p=0.341 n=20
Memory Allocs 3,991,706 (± 0.13%) 3,991,162 (± 0.09%) ~ 3,980,657 4,008,421 p=0.883 n=20
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=20
Parse Time 0.064s (± 3.36%) 0.065s (± 3.34%) ~ 0.059s 0.073s p=0.335 n=20
Bind Time 0.022s (± 9.97%) 0.022s (± 9.70%) ~ 0.018s 0.034s p=0.770 n=20
Check Time 0.428s (± 0.88%) 0.425s (± 1.04%) ~ 0.409s 0.444s p=0.350 n=20
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=20
Total Time 0.519s (± 0.97%) 0.519s (± 1.09%) ~ 0.502s 0.542s p=0.920 n=20
System info unknown
Hosts
  • native
Scenarios
  • Compiler-Unions - native
  • angular-1 - native
  • arktype - native
  • class-transformer - native
  • effect - native
  • mui-docs - native
  • sentry - native
  • social-app - native
  • strada-build-src - native
  • strada-compiler - native
  • t3code-server - native
  • tanstack-router - native
  • ts-pre-modules - native
  • vscode - native
  • webpack - native
  • xstate-main - native
Benchmark Name Iterations
Current pr 20
Baseline baseline 20

Developer Information:

Download Benchmarks

@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Oct 30, 2026

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 Domain: Performance Reports of unusually slow behavior For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Needs merge

Development

Successfully merging this pull request may close these issues.

3 participants