Skip to content

Presize checker type-list cache keys - #64777

Merged
Jake Bailey (jakebailey) merged 1 commit into
jakebailey/mem/compressed-link-storesfrom
jakebailey/mem/presized-type-list-keys
Oct 13, 2026
Merged

Jake Bailey (jakebailey) merged 1 commit into
jakebailey/mem/compressed-link-storesfrom
jakebailey/mem/presized-type-list-keys

Conversation

@jakebailey

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

Copy link
Copy Markdown
Member

Large type lists repeatedly grow temporary hash buffers even though their encoded size is known up front.

  • Reserves the known size before encoding; the hash byte stream is unchanged.
  • For a 4,096-element key, allocations fall 13 → 1 and allocated bytes fall 77.85%.
  • Small keys keep their allocation-free path.

Part of the memory optimization stack summarized in #64734.

@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 13, 2026
@jakebailey
Jake Bailey (jakebailey) added this pull request to stack #64792 October 13, 2026 17:37
@jakebailey Jake Bailey (jakebailey) changed the title Presize checker type-list cache keys Presize checker type-list cache keys Large type lists repeatedly grow temporary hash buffers even though their encoded size is known up front. - Reserves the known size before encoding; the hash byte stream is unchanged. - For a 4,096-element key, allocations fall **13 → 1** and allocated bytes fall **77.85%**. - Small keys keep their allocation-free path. Oct 13, 2026
@jakebailey Jake Bailey (jakebailey) changed the title Presize checker type-list cache keys Large type lists repeatedly grow temporary hash buffers even though their encoded size is known up front. - Reserves the known size before encoding; the hash byte stream is unchanged. - For a 4,096-element key, allocations fall **13 → 1** and allocated bytes fall **77.85%**. - Small keys keep their allocation-free path. Presize checker type-list cache keys Oct 13, 2026
@jakebailey
Jake Bailey (jakebailey) marked this pull request as ready for review October 13, 2026 17:42
Copilot AI balanced review requested due to automatic review settings October 13, 2026 17:42

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 reservation logic preserves byte-stream behavior and is covered across inline and overflow boundaries.

0 open findings

What changed in this PR

Presizes checker cache-key buffers to avoid repeated allocations while preserving encoded hashes.

Changes:

  • Adds capacity reservation for type-list encoding.
  • Tests hash stability and allocation boundaries.
  • Adds focused allocation benchmarks.
File Description
tsc/​internal/​checker/​checker.go Reserves type-list key capacity before encoding.
tsc/​internal/​checker/​types_test.go Adds correctness, allocation, and benchmark coverage.
tsc/​internal/​checker/​checker_test.go Benchmarks fresh-program checking.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Large type lists repeatedly grow temporary hash buffers even though
their encoded length is already known. These discarded allocations
account for a substantial part of checker allocation traffic.

Reserve enough capacity before writing each list, retaining the small
inline path and the exact existing hash byte stream. Allocation tests
cover the inline boundary and large lists, and a fresh-program benchmark
includes parsing and binding rather than relying only on warmed ASTs.

CPU wall timings are noisy on this machine; report bytes and allocation
counts instead.

goos: linux
goarch: amd64
pkg: github.com/microsoft/TypeScript/tsc/internal/checker
cpu: Intel(R) Core(TM) i9-10900K CPU @ 3.70GHz
                    │ key-before.txt │            key-reserve.txt            │
                    │      B/op      │     B/op      vs base                 │
TypeListKey/8-20        0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=6) ¹
TypeListKey/46-20       0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=6) ¹
TypeListKey/47-20       576.0 ± 0%       208.0 ± 0%  -63.89% (p=0.002 n=6)
TypeListKey/256-20    2.375Ki ± 0%     1.125Ki ± 0%  -52.63% (p=0.002 n=6)
TypeListKey/4096-20   81.25Ki ± 0%     18.00Ki ± 0%  -77.85% (p=0.002 n=6)
geomean                            ²                 -48.03%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                    │ key-before.txt │           key-reserve.txt           │
                    │   allocs/op    │ allocs/op   vs base                 │
TypeListKey/8-20        0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=6) ¹
TypeListKey/46-20       0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=6) ¹
TypeListKey/47-20       2.000 ± 0%     1.000 ± 0%  -50.00% (p=0.002 n=6)
TypeListKey/256-20      4.000 ± 0%     1.000 ± 0%  -75.00% (p=0.002 n=6)
TypeListKey/4096-20    13.000 ± 0%     1.000 ± 0%  -92.31% (p=0.002 n=6)
geomean                            ²               -60.50%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean
@jakebailey
Jake Bailey (jakebailey) force-pushed the jakebailey/mem/presized-type-list-keys branch from 2a39414 to 161e925 Compare October 13, 2026 20:06
Base automatically changed from jakebailey/mem/batched-type-allocs to jakebailey/mem/compressed-link-stores October 13, 2026 20:06
@jakebailey
Jake Bailey (jakebailey) deleted the jakebailey/mem/presized-type-list-keys branch October 13, 2026 20:06
@jakebailey
Jake Bailey (jakebailey) restored the jakebailey/mem/presized-type-list-keys branch October 13, 2026 20:15
@jakebailey
Jake Bailey (jakebailey) deleted the jakebailey/mem/presized-type-list-keys branch October 14, 2026 01:07
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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants