Repository navigation
Reuse ordered property counts during intersection reduction - #64804
Merged
Jake Bailey (jakebailey) merged 2 commits intoOct 14, 2026
Conversation
Jake Bailey (jakebailey)
added this pull request to stack #64805
October 13, 2026 20:16
Jake Bailey (jakebailey)
removed this pull request from stack #64805
October 13, 2026 20:49
Jake Bailey (jakebailey)
added this pull request to stack #64806
October 13, 2026 20:50
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The reuse logic preserves existing semantics and is covered by focused allocation and reentrancy tests.
0 open findings
What changed in this PR
Reuses checker-local ordered property-count maps to eliminate allocations during intersection reduction while preserving ordering and recursive isolation.
Changes:
- Adds bounded reusable property-count storage.
- Uses pooled storage during intersection reduction.
- Adds allocation, reuse, ordering, and reentrancy tests.
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Uses temporary property-count storage. |
tsc/internal/checker/utilities.go |
Implements bounded storage reuse. |
tsc/internal/checker/types_test.go |
Tests allocations and lifecycle safety. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Jake Bailey (jakebailey)
force-pushed
the
jakebailey/mem/intersection-count-reuse
branch
from
October 13, 2026 21:39
fd19cf8 to
1ba59d2
Compare
Anders Hejlsberg (ahejlsberg)
approved these changes
Oct 14, 2026
Jake Bailey (jakebailey)
force-pushed
the
jakebailey/mem/intersection-count-reuse
branch
from
October 14, 2026 01:07
1ba59d2 to
1482441
Compare
Jake Bailey (jakebailey)
force-pushed
the
jakebailey/mem/intersection-count-reuse
branch
from
October 14, 2026 02:23
1482441 to
0e717e2
Compare
Jake Bailey (jakebailey)
requested a review
from Anders Hejlsberg (ahejlsberg)
October 14, 2026 02:31
Member
|
Weird that we need a free list. Maybe it's worth exploring a pool of 16, a bitset that indicates which one is currently in use, and just allocates if they're all occupied. |
Daniel Rosenwasser (DanielRosenwasser)
approved these changes
Oct 14, 2026
Daniel Rosenwasser (DanielRosenwasser)
left a comment
Member
There was a problem hiding this comment.
Anyway, optimization is optimization.
Anders Hejlsberg (ahejlsberg)
approved these changes
Oct 14, 2026
Anders Hejlsberg (ahejlsberg)
force-pushed
the
jakebailey/mem/intersection-count-reuse
branch
from
October 14, 2026 14:14
0e717e2 to
28400fe
Compare
Resolved type nodes and signatures still kept AST pointers as map keys
despite already having stable node identities. Those maps add redundant
pointer storage, GC scanning, hashing, and growth allocations.
Reuse the existing node-link store's pointer-free paged indexes for
these two high-volume caches. Ordinary IDs and IDs outside the dense
reserved range retain the existing fallback, and caches stay
checker-local.
Six fresh-process interleaved VS Code comparisons against the parent
commit, using normal GC, reduce retained heap 1.20%, scan bytes 2.12%,
allocated bytes 2.11%, and allocation events 0.20%. Instructions are
inconclusive. This saves another roughly 43 MiB of heap and 66 MiB of
scanning.
Production diagnostics and semantic counts match exactly. Tests cover
cache identity, ordinary/reserved IDs, clone isolation, growth,
GC reachability, and independent checkers.
goos: linux
goarch: amd64
pkg: github.com/microsoft/TypeScript/tsc/internal/checker
cpu: Intel(R) Core(TM) i9-10900K CPU @ 3.70GHz
│ vscode-paged-before-6.txt │ vscode-paged-6.txt │
│ retained-B │ retained-B vs base │
ExternalProgram-20 3.497Gi ± 0% 3.455Gi ± 0% -1.20% (p=0.002 n=6)
│ vscode-paged-before-6.txt │ vscode-paged-6.txt │
│ scan-B │ scan-B vs base │
ExternalProgram-20 3.061Gi ± 0% 2.997Gi ± 0% -2.12% (p=0.002 n=6)
│ vscode-paged-before-6.txt │ vscode-paged-6.txt │
│ B/op │ B/op vs base │
ExternalProgram-20 5.129Gi ± 0% 5.021Gi ± 0% -2.11% (p=0.002 n=6)
│ vscode-paged-before-6.txt │ vscode-paged-6.txt │
│ allocs/op │ allocs/op vs base │
ExternalProgram-20 31.16M ± 0% 31.09M ± 0% -0.20% (p=0.002 n=6)
│ paged-before-instructions.txt │ paged-instructions.txt │
│ instructions/op │ instructions/op vs base │
ExternalInstructions-20 279.8G ± 5% 270.5G ± 2% ~ (p=0.589 n=6)
Intersection reduction repeatedly allocates temporary property-count
tables. On MUI, this one allocation site accounts for roughly a quarter
of all allocated bytes, despite none of the tables needing to survive
the reduction. Reusing this workspace removes substantial allocation
churn without changing the first-seen property order or caching results.
Each recursive reduction borrows an independent checker-local table.
Returning a table clears its names and counts, including on early
returns; tables exceeding 4096 properties are not retained.
Against the parent commit, six fresh-process MUI single-checker pairs
save 1.36 GiB of allocation per run, reduce allocation events by 7.59%,
and reduce instructions by 6.02%. Default-threaded production MUI
instructions decrease 8.88%. Retained heap and scannable heap are
essentially unchanged: this is an allocation-churn optimization.
VS Code allocation savings are smaller. Production VS Code instructions
remain inconclusive after twelve pairs, with a higher point estimate;
Webpack instructions are also inconclusive. Wall times are noisy on
this shared host. All production diagnostic text and semantic counts
match between revisions.
The regression test allocated 21 times per warmed reduction before this
change and now allocates zero times. Tests also cover nested borrowing,
property order, clearing, oversized tables, and early-return cleanup.
Six fresh-process single-checker pairs, ordinary GC:
│ mui-property-counts-memory-before.txt │ mui-property-counts-memory-after.txt │
│ retained-B │ retained-B vs base │
ExternalMemory-20 1.492Gi ± 0% 1.492Gi ± 0% ~ (p=0.310 n=6)
│ mui-property-counts-memory-before.txt │ mui-property-counts-memory-after.txt │
│ scan-B │ scan-B vs base │
ExternalMemory-20 1.270Gi ± 0% 1.270Gi ± 0% ~ (p=0.310 n=6)
│ mui-property-counts-memory-before.txt │ mui-property-counts-memory-after.txt │
│ B/op │ B/op vs base │
ExternalMemory-20 5.122Gi ± 0% 3.757Gi ± 0% -26.64% (p=0.002 n=6)
│ mui-property-counts-memory-before.txt │ mui-property-counts-memory-after.txt │
│ allocs/op │ allocs/op vs base │
ExternalMemory-20 24.77M ± 0% 22.89M ± 0% -7.59% (p=0.002 n=6)
│ mui-property-counts-memory-before.instructions │ mui-property-counts-memory-after.instructions │
│ instructions/op │ instructions/op vs base │
mui-20 213.7G ± 3% 200.8G ± 3% -6.02% (p=0.002 n=6)
│ vscode-property-counts-memory-before.txt │ vscode-property-counts-memory-after.txt │
│ retained-B │ retained-B vs base │
ExternalMemory-20 2.615Gi ± 0% 2.615Gi ± 0% ~ (p=0.589 n=6)
│ vscode-property-counts-memory-before.txt │ vscode-property-counts-memory-after.txt │
│ scan-B │ scan-B vs base │
ExternalMemory-20 2.287Gi ± 0% 2.287Gi ± 0% ~ (p=0.589 n=6)
│ vscode-property-counts-memory-before.txt │ vscode-property-counts-memory-after.txt │
│ B/op │ B/op vs base │
ExternalMemory-20 3.749Gi ± 0% 3.714Gi ± 0% -0.92% (p=0.002 n=6)
│ vscode-property-counts-memory-before.txt │ vscode-property-counts-memory-after.txt │
│ allocs/op │ allocs/op vs base │
ExternalMemory-20 23.60M ± 0% 23.49M ± 0% -0.47% (p=0.002 n=6)
│ vscode-property-counts-memory-before.instructions │ vscode-property-counts-memory-after.instructions │
│ instructions/op │ instructions/op vs base │
vscode-20 193.0G ± 4% 193.2G ± 5% ~ (p=0.818 n=6)
Default-threaded production CLI (six pairs; VS Code twelve pairs):
│ mui-property-counts-cli-before.txt │ mui-property-counts-cli-after.txt │
│ heap-B/op │ heap-B/op vs base │
mui-20 1.867Gi ± 0% 1.868Gi ± 0% ~ (p=0.589 n=6)
│ mui-property-counts-cli-before.txt │ mui-property-counts-cli-after.txt │
│ allocs/op │ allocs/op vs base │
mui-20 29.52M ± 0% 27.84M ± 0% -5.69% (p=0.002 n=6)
│ mui-property-counts-cli-before.txt │ mui-property-counts-cli-after.txt │
│ check-sec/op │ check-sec/op vs base │
mui-20 11.59 ± 3% 10.67 ± 5% -7.86% (p=0.004 n=6)
│ mui-property-counts-cli-before.instructions │ mui-property-counts-cli-after.instructions │
│ instructions/op │ instructions/op vs base │
mui-20 274.6G ± 2% 250.2G ± 4% -8.88% (p=0.002 n=6)
│ vscode-property-counts-cli-before.txt │ vscode-property-counts-cli-after.txt │
│ heap-B/op │ heap-B/op vs base │
vscode-20 2.828Gi ± 0% 2.828Gi ± 0% ~ (p=0.843 n=12)
│ vscode-property-counts-cli-before.txt │ vscode-property-counts-cli-after.txt │
│ allocs/op │ allocs/op vs base │
vscode-20 36.62M ± 0% 36.54M ± 0% -0.21% (p=0.000 n=12)
│ vscode-property-counts-cli-before.txt │ vscode-property-counts-cli-after.txt │
│ check-sec/op │ check-sec/op vs base │
vscode-20 8.671 ± 21% 8.409 ± 26% ~ (p=0.799 n=12)
│ vscode-property-counts-cli-before.instructions │ vscode-property-counts-cli-after.instructions │
│ instructions/op │ instructions/op vs base │
vscode-20 296.5G ± 4% 307.6G ± 3% ~ (p=0.242 n=12)
│ webpack-property-counts-cli-before.txt │ webpack-property-counts-cli-after.txt │
│ heap-B/op │ heap-B/op vs base │
webpack-20 663.0Mi ± 0% 663.1Mi ± 0% ~ (p=0.699 n=6)
│ webpack-property-counts-cli-before.txt │ webpack-property-counts-cli-after.txt │
│ allocs/op │ allocs/op vs base │
webpack-20 6.208M ± 0% 6.096M ± 0% -1.80% (p=0.002 n=6)
│ webpack-property-counts-cli-before.txt │ webpack-property-counts-cli-after.txt │
│ check-sec/op │ check-sec/op vs base │
webpack-20 1.765 ± 8% 1.711 ± 6% ~ (p=0.180 n=6)
│ webpack-property-counts-cli-before.instructions │ webpack-property-counts-cli-after.instructions │
│ instructions/op │ instructions/op vs base │
webpack-20 52.37G ± 2% 51.78G ± 3% ~ (p=0.394 n=6)
Jake Bailey (jakebailey)
force-pushed
the
jakebailey/mem/intersection-count-reuse
branch
from
October 14, 2026 14:17
28400fe to
e9ef3a7
Compare
Anders Hejlsberg (ahejlsberg)
approved these changes
Oct 14, 2026
Ryan Cavanaugh (RyanCavanaugh)
approved these changes
Oct 14, 2026
Base automatically changed from
jakebailey/mem/indexed-type-node-caches
to
jakebailey/mem/byte-sized-arena-chunks
October 14, 2026 16:02
Jake Bailey (jakebailey)
deleted the
jakebailey/mem/intersection-count-reuse
branch
October 14, 2026 16:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intersection reduction allocates temporary property-count tables; on MUI this one site is about a quarter of all allocated bytes.
Part of the memory optimization stack summarized in #64734.
Replaces #64790, which GitHub closed as merged when the stack was reordered.