Skip to content

Speed up union subset checks by scanning sorted constituents - #64964

Merged
Daniel Rosenwasser (DanielRosenwasser) merged 3 commits into
microsoft:mainfrom
Andarist:andarist/sorted-subset-union-scan
Oct 28, 2026
Merged

Daniel Rosenwasser (DanielRosenwasser) merged 3 commits into
microsoft:mainfrom
Andarist:andarist/sorted-subset-union-scan

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI balanced review requested due to automatic review settings October 25, 2026 22:50
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 25, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 25, 2026
@typescript-automation

Copy link
Copy Markdown
Contributor

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

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.

🟡 Changes recommended

Sparse subset checks now require linear rather than logarithmic search work against large target unions.

1 open issue
What changed in this PR

This PR changes union-subset checking in the native TypeScript checker to use a forward identity scan instead of repeated binary searches.

Changes:

  • Rejects source unions with more members than the target.
  • Searches progressively shorter target slices, relying on sorted union members.
File Description
tsc/​internal/​checker/​relater.go Replaces per-member binary searches with a forward scan and adds a size guard.

Review effort: Balanced

Comment thread tsc/internal/checker/relater.go Outdated

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 change preserves subset semantics under the established sorted, deduplicated union invariant, with no blocking issues identified.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@Andarist
Mateusz Burzyński (Andarist) force-pushed the andarist/sorted-subset-union-scan branch from 69739e1 to d2050ae Compare October 26, 2026 07:06
@Andarist Mateusz Burzyński (Andarist) changed the title Check union subsets with a forward identity scan instead of binary searches Speed up union subset checks by scanning sorted constituents Oct 26, 2026
@jakebailey

This comment has been minimized.

@typescript-automation

This comment has been minimized.

@typescript-automation

This comment has been minimized.

@Andarist
Mateusz Burzyński (Andarist) force-pushed the andarist/sorted-subset-union-scan branch from d2050ae to 4c35db3 Compare October 26, 2026 09:22
@jakebailey

This comment has been minimized.

@typescript-automation

This comment has been minimized.

@typescript-automation

This comment has been minimized.

@DanielRosenwasser

This comment has been minimized.

@typescript-automation

This comment has been minimized.

}
return true
}
for _, t := range sourceTypes {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
for _, t := range sourceTypes {
for _, t := range sourceTypes {

@typescript-automation

This comment has been minimized.

@jakebailey

Copy link
Copy Markdown
Member

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

@typescript-automation

typescript-automation Bot commented Oct 26, 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 perf run you requested failed. You can check the log here.

@jakebailey

Copy link
Copy Markdown
Member

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

@typescript-automation

typescript-automation Bot commented Oct 26, 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 perf run you requested failed. You can check the log here.

@typescript-automation

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey)
The results of the perf run you requested are in!

Here they are:

Provisional hosted-runner results: these VMs are not the dedicated benchmark machines. Results may be noisier and are not comparable to the historical series. For comparisons, both revisions of each scenario ran on the same VM.

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 88,466 88,466 ~ ~ ~ p=1.000 n=12
Types 79,607 79,607 ~ ~ ~ p=1.000 n=12
Memory Used 109,254k (± 0.08%) 109,206k (± 0.06%) ~ 109,051k 109,398k p=0.744 n=12
Memory Allocs 2,196,809 (± 0.00%) 2,196,703 (± 0.01%) ~ 2,196,481 2,197,142 p=0.110 n=12
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Parse Time 0.042s (± 3.52%) 0.043s (± 3.75%) ~ 0.037s 0.045s p=0.448 n=12
Bind Time 0.018s (± 9.40%) 0.019s (±11.73%) ~ 0.015s 0.026s p=0.616 n=12
Check Time 0.445s (± 1.88%) 0.405s (± 3.44%) 🟩-0.039s (- 8.88%) 0.381s 0.454s p=0.000 n=12
Emit Time 0.298s (± 3.46%) 0.283s (± 2.83%) 🟩-0.015s (- 4.92%) 0.265s 0.306s p=0.015 n=12
Total Time 0.809s (± 1.29%) 0.757s (± 2.70%) 🟩-0.053s (- 6.50%) 0.727s 0.833s p=0.000 n=12
angular-1 - native
Errors 3 3 ~ ~ ~ p=1.000 n=12
Symbols 586,578 (± 0.03%) 586,535 (± 0.02%) ~ 586,028 586,854 p=0.977 n=12
Types 241,692 (± 0.00%) 241,692 (± 0.00%) ~ 241,688 241,695 p=0.535 n=12
Memory Used 551,150k (± 0.03%) 551,084k (± 0.02%) ~ 550,811k 551,368k p=0.478 n=12
Memory Allocs 13,073,246 (± 0.04%) 13,070,127 (± 0.01%) ~ 13,066,693 13,074,471 p=0.977 n=12
Config Time 0.017s (± 2.46%) 0.017s (± 2.33%) ~ 0.016s 0.018s p=0.199 n=12
Parse Time 0.194s (± 4.63%) 0.192s (± 5.47%) ~ 0.174s 0.229s p=0.504 n=12
Bind Time 0.058s (±12.45%) 0.057s (±12.81%) ~ 0.050s 0.084s p=0.291 n=12
Check Time 0s 0s ~ ~ ~ p=1.000 n=12
Emit Time 1.157s (± 1.47%) 1.160s (± 0.95%) ~ 1.137s 1.197s p=0.989 n=12
Total Time 1.440s (± 1.48%) 1.439s (± 1.01%) ~ 1.415s 1.480s p=0.854 n=12
arktype - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 685,943 685,943 ~ ~ ~ p=1.000 n=12
Types 939,490 939,490 ~ ~ ~ p=1.000 n=12
Memory Used 533,269k (± 0.01%) 533,143k (± 0.01%) -126k (- 0.02%) 533,042k 533,352k p=0.000 n=12
Memory Allocs 12,772,465 (± 0.02%) 12,770,075 (± 0.01%) ~ 12,768,064 12,775,734 p=0.089 n=12
Config Time 0.002s 0.002s ~ ~ ~ p=1.000 n=12
Parse Time 0.061s (± 4.11%) 0.061s (± 5.31%) ~ 0.053s 0.070s p=1.000 n=12
Bind Time 0.020s (±11.92%) 0.019s (± 9.34%) ~ 0.016s 0.026s p=0.989 n=12
Check Time 1.397s (± 0.69%) 1.382s (± 0.32%) -0.015s (- 1.07%) 1.368s 1.392s p=0.003 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 1.518s (± 0.60%) 1.504s (± 0.39%) -0.014s (- 0.93%) 1.490s 1.521s p=0.014 n=12
mui-docs - native
Errors 11,405 11,405 ~ ~ ~ p=1.000 n=12
Symbols 3,784,027 3,784,027 ~ ~ ~ p=1.000 n=12
Types 1,355,982 1,355,982 ~ ~ ~ p=1.000 n=12
Memory Used 2,197,614k (± 0.08%) 2,198,870k (± 0.08%) ~ 2,194,860k 2,203,450k p=0.266 n=12
Memory Allocs 26,469,431 (± 0.06%) 26,474,423 (± 0.09%) ~ 26,410,711 26,558,487 p=0.755 n=12
Config Time 0.014s (± 2.00%) 0.014s (± 1.29%) ~ 0.014s 0.015s p=0.590 n=12
Parse Time 0.495s (± 2.96%) 0.504s (± 2.38%) ~ 0.459s 0.522s p=0.272 n=12
Bind Time 0.002s (±21.90%) 0.001s (±22.86%) ~ 0.001s 0.002s p=1.000 n=12
Check Time 4.808s (± 0.38%) 4.817s (± 0.38%) ~ 4.758s 4.865s p=0.434 n=12
Emit Time 0.370s (± 5.00%) 0.364s (± 5.04%) ~ 0.336s 0.399s p=0.467 n=12
Total Time 6.497s (± 0.79%) 6.484s (± 0.54%) ~ 6.417s 6.631s p=1.000 n=12
sentry - native
Errors 2 2 ~ ~ ~ p=1.000 n=12
Symbols 4,793,249 4,793,249 ~ ~ ~ p=1.000 n=12
Types 2,607,051 2,607,051 ~ ~ ~ p=1.000 n=12
Memory Used 3,206,139k (± 0.05%) 3,206,534k (± 0.06%) ~ 3,203,701k 3,212,410k p=0.843 n=12
Memory Allocs 75,290,910 (± 0.10%) 75,268,233 (± 0.11%) ~ 75,034,163 75,534,626 p=0.843 n=12
Config Time 0.044s 0.045s (± 0.73%) +0.001s (+ 1.33%) 0.044s 0.045s p=0.005 n=12
Parse Time 0.687s (± 1.51%) 0.700s (± 4.25%) ~ 0.639s 0.801s p=0.723 n=12
Bind Time 0.195s (±12.72%) 0.202s (±10.93%) ~ 0.174s 0.286s p=0.181 n=12
Check Time 9.281s (± 0.45%) 9.295s (± 0.42%) ~ 9.199s 9.431s p=0.434 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 10.264s (± 0.49%) 10.303s (± 0.44%) ~ 10.174s 10.385s p=0.143 n=12
social-app - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 1,883,075 1,883,075 ~ ~ ~ p=1.000 n=12
Types 1,158,171 1,158,171 ~ ~ ~ p=1.000 n=12
Memory Used 1,056,677k (± 0.02%) 1,056,904k (± 0.02%) ~ 1,055,912k 1,057,272k p=0.101 n=12
Memory Allocs 13,570,757 (± 0.11%) 13,584,287 (± 0.16%) ~ 13,538,818 13,639,793 p=0.478 n=12
Config Time 0.015s (± 2.22%) 0.015s (± 2.22%) ~ 0.014s 0.015s p=1.000 n=12
Parse Time 0.237s (± 2.16%) 0.247s (± 1.97%) 🔻+0.010s (+ 4.26%) 0.239s 0.263s p=0.019 n=12
Bind Time 0.057s (±11.28%) 0.052s (±10.32%) ~ 0.046s 0.078s p=0.338 n=12
Check Time 2.151s (± 0.25%) 2.148s (± 0.54%) ~ 2.125s 2.186s p=0.224 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 2.479s (± 0.46%) 2.479s (± 0.49%) ~ 2.452s 2.513s p=0.991 n=12
strada-build-src - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 1,184,976 1,184,976 ~ ~ ~ p=1.000 n=12
Types 438,967 438,967 ~ ~ ~ p=1.000 n=12
Memory Used 1,257,581k (± 0.45%) 1,259,940k (± 0.34%) ~ 1,248,240k 1,268,285k p=0.590 n=12
Memory Allocs 76,894,331 (± 0.15%) 76,930,792 (± 0.19%) ~ 76,632,349 77,366,767 p=0.443 n=12
Config Time 0.004s (±18.41%) 0.004s (±10.74%) ~ 0.003s 0.005s p=0.617 n=12
Parse Time 0.180s (± 1.64%) 0.180s (± 2.05%) ~ 0.169s 0.190s p=0.876 n=12
Bind Time 0.000s 0.000s (±217.90%) ~ 0.000s 0.002s p=1.000 n=12
Check Time 1.189s (± 0.38%) 1.099s (± 0.48%) 🟩-0.090s (- 7.57%) 1.087s 1.117s p=0.000 n=12
Emit Time 0.212s (± 1.41%) 0.216s (± 2.33%) ~ 0.204s 0.231s p=0.339 n=12
Total Time 14.020s (± 0.52%) 13.215s (± 0.45%) 🟩-0.805s (- 5.74%) 13.056s 13.324s p=0.000 n=12
strada-compiler - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 263,513 263,513 ~ ~ ~ p=1.000 n=12
Types 196,118 196,118 ~ ~ ~ p=1.000 n=12
Memory Used 236,088k (± 0.02%) 236,126k (± 0.02%) ~ 235,977k 236,219k p=0.139 n=12
Memory Allocs 4,287,635 (± 0.01%) 4,287,759 (± 0.01%) ~ 4,286,942 4,288,773 p=1.000 n=12
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=12
Parse Time 0.073s (± 4.42%) 0.073s (± 5.31%) ~ 0.064s 0.082s p=1.000 n=12
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Check Time 0.605s (± 0.69%) 0.564s (± 1.37%) 🟩-0.041s (- 6.81%) 0.551s 0.588s p=0.000 n=12
Emit Time 0.095s (± 2.87%) 0.096s (± 1.75%) ~ 0.092s 0.101s p=0.540 n=12
Total Time 0.813s (± 0.72%) 0.771s (± 0.92%) 🟩-0.042s (- 5.13%) 0.760s 0.796s p=0.000 n=12
t3code-server - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 4,350,705 4,350,705 ~ ~ ~ p=1.000 n=12
Types 3,040,691 3,040,691 ~ ~ ~ p=1.000 n=12
Memory Used 2,610,578k (± 0.03%) 2,610,261k (± 0.02%) ~ 2,609,369k 2,611,592k p=0.443 n=12
Memory Allocs 37,339,381 (± 0.06%) 37,316,938 (± 0.03%) ~ 37,273,558 37,346,783 p=0.198 n=12
Config Time 0.005s 0.005s (± 7.03%) ~ 0.005s 0.007s p=1.000 n=12
Parse Time 0.371s (± 3.63%) 0.389s (± 3.16%) 🔻+0.018s (+ 4.92%) 0.357s 0.418s p=0.046 n=12
Bind Time 0.125s (±11.77%) 0.114s (± 2.85%) ~ 0.108s 0.124s p=0.701 n=12
Check Time 11.023s (± 0.57%) 11.097s (± 0.69%) ~ 10.918s 11.259s p=0.160 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 11.538s (± 0.52%) 11.619s (± 0.64%) ~ 11.453s 11.799s p=0.114 n=12
ts-pre-modules - native
Errors 87 87 ~ ~ ~ p=1.000 n=12
Symbols 231,617 231,617 ~ ~ ~ p=1.000 n=12
Types 181,196 181,196 ~ ~ ~ p=1.000 n=12
Memory Used 203,537k (± 0.02%) 203,548k (± 0.02%) ~ 203,467k 203,654k p=0.932 n=12
Memory Allocs 1,358,061 (± 0.01%) 1,358,187 (± 0.01%) ~ 1,357,978 1,358,488 p=0.078 n=12
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Parse Time 0.062s (± 4.48%) 0.063s (± 4.04%) ~ 0.057s 0.070s p=0.700 n=12
Bind Time 0.027s (± 5.40%) 0.028s (± 5.12%) ~ 0.024s 0.032s p=0.385 n=12
Check Time 0.462s (± 0.70%) 0.424s (± 0.53%) 🟩-0.038s (- 8.29%) 0.419s 0.430s p=0.000 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 0.562s (± 0.70%) 0.526s (± 0.64%) 🟩-0.037s (- 6.52%) 0.517s 0.534s p=0.000 n=12
vscode - native
Errors 10 10 ~ ~ ~ p=1.000 n=12
Symbols 7,281,695 7,281,695 ~ ~ ~ p=1.000 n=12
Types 4,286,835 4,286,835 ~ ~ ~ p=1.000 n=12
Memory Used 5,404,544k (± 0.02%) 5,405,000k (± 0.02%) ~ 5,402,941k 5,407,436k p=0.291 n=12
Memory Allocs 62,550,682 (± 0.01%) 62,554,333 (± 0.01%) ~ 62,546,073 62,574,884 p=0.590 n=12
Config Time 0.068s (± 0.39%) 0.068s (± 0.54%) ~ 0.067s 0.069s p=0.496 n=12
Parse Time 1.249s (± 1.59%) 1.250s (± 1.64%) ~ 1.167s 1.292s p=0.843 n=12
Bind Time 0.416s (± 9.24%) 0.417s (± 9.92%) ~ 0.386s 0.615s p=0.723 n=12
Check Time 11.300s (± 0.34%) 11.237s (± 0.49%) ~ 11.073s 11.402s p=0.058 n=12
Emit Time 3.829s (± 3.73%) 3.801s (± 4.58%) ~ 3.576s 4.329s p=0.443 n=12
Total Time 16.930s (± 0.82%) 16.842s (± 0.96%) ~ 16.591s 17.318s p=0.219 n=12
webpack - native
Errors 617 617 ~ ~ ~ p=1.000 n=12
Symbols 922,055 922,055 ~ ~ ~ p=1.000 n=12
Types 644,701 644,701 ~ ~ ~ p=1.000 n=12
Memory Used 776,140k (± 0.03%) 776,186k (± 0.01%) ~ 775,896k 776,502k p=0.541 n=12
Memory Allocs 6,570,809 (± 0.01%) 6,571,823 (± 0.02%) ~ 6,570,225 6,577,253 p=0.259 n=12
Config Time 0.007s 0.007s ~ ~ ~ p=1.000 n=12
Parse Time 0.201s (± 4.54%) 0.203s (± 4.13%) ~ 0.183s 0.223s p=0.944 n=12
Bind Time 0.063s (±11.94%) 0.064s (±13.06%) ~ 0.051s 0.085s p=0.578 n=12
Check Time 1.693s (± 0.45%) 1.674s (± 0.49%) -0.019s (- 1.12%) 1.652s 1.692s p=0.001 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 1.998s (± 0.51%) 1.982s (± 0.44%) -0.016s (- 0.80%) 1.953s 2.001s p=0.016 n=12
xstate-main - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 640,494 640,494 ~ ~ ~ p=1.000 n=12
Types 387,992 387,992 ~ ~ ~ p=1.000 n=12
Memory Used 398,375k (± 0.03%) 398,492k (± 0.04%) ~ 398,241k 399,021k p=0.198 n=12
Memory Allocs 3,989,975 (± 0.10%) 3,991,090 (± 0.09%) ~ 3,983,271 4,000,838 p=0.932 n=12
Config Time 0.002s 0.002s ~ ~ ~ p=1.000 n=12
Parse Time 0.088s (± 1.98%) 0.088s (± 3.20%) ~ 0.080s 0.094s p=0.899 n=12
Bind Time 0.027s (± 8.76%) 0.027s (±11.17%) ~ 0.023s 0.037s p=0.720 n=12
Check Time 0.618s (± 0.97%) 0.613s (± 0.87%) ~ 0.600s 0.627s p=0.202 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 0.742s (± 0.85%) 0.737s (± 0.95%) ~ 0.721s 0.750s p=0.271 n=12
System info unknown
Hosts
  • native
Scenarios
  • Compiler-Unions - native
  • angular-1 - native
  • arktype - native
  • mui-docs - native
  • sentry - native
  • social-app - native
  • strada-build-src - native
  • strada-compiler - native
  • t3code-server - 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

@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Oct 27, 2026
Merged via the queue into microsoft:main with commit 97aedd3 Oct 28, 2026
29 checks passed
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Domain: Performance Reports of unusually slow behavior For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants