Skip to content

Presize checker type-list cache keys - #64794

Merged
Jake Bailey (jakebailey) merged 1 commit into
jakebailey/mem/batched-type-allocsfrom
jakebailey/mem/presized-type-list-keys
Oct 14, 2026
Merged

Jake Bailey (jakebailey) merged 1 commit into
jakebailey/mem/batched-type-allocsfrom
jakebailey/mem/presized-type-list-keys

Conversation

@jakebailey

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.

Replaces #64777, which GitHub closed as merged when the stack was reordered.

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

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 encoding behavior and has focused correctness and allocation coverage.

0 open findings

What changed in this PR

Presizes checker type-list cache keys to reduce temporary buffer allocations without changing hashes.

Changes:

  • Reserves encoded type-list capacity before writing.
  • Adds hash-correctness and allocation-boundary tests.
  • Adds focused key and fresh-program benchmarks.
File Description
tsc/​internal/​checker/​checker.go Presizes overflow buffers for type-list keys.
tsc/​internal/​checker/​types_test.go Tests correctness and allocation behavior.
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.

@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Oct 13, 2026
@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit 9eedcb0 Oct 14, 2026
101 of 102 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the jakebailey/mem/presized-type-list-keys branch October 14, 2026 01:07
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Oct 14, 2026
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: Done

Development

Successfully merging this pull request may close these issues.

3 participants