Skip to content

Move optional structured type shape into cold storage - #64784

Merged
Jake Bailey (jakebailey) merged 1 commit into
jakebailey/mem/compact-member-indexesfrom
jakebailey/mem/cold-structured-types
Oct 13, 2026
Merged

Jake Bailey (jakebailey) merged 1 commit into
jakebailey/mem/compact-member-indexesfrom
jakebailey/mem/cold-structured-types

Conversation

@jakebailey

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

Copy link
Copy Markdown
Member

Every object, union, and intersection reserved space for signatures, index infos, and a node-builder cache, even when unused.

  • Moves them into optional checker-arena storage; StructuredType shrinks 144 → 88 bytes.
  • Historical VS Code measurements showed 1.81% less retained heap and 2.01% less GC scanning.
  • Keeps ordinary eager member resolution.

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) changed the title Move optional structured type shape into cold storage Oct 13, 2026
@jakebailey Jake Bailey (jakebailey) changed the title Move optional structured type shape into cold storage Every object, union, and intersection reserved space for signatures, index infos, and a node-builder cache, even when unused. - Moves them into optional checker-arena storage; StructuredType shrinks **144 → 88 bytes**. - Historical VS Code measurements showed **1.81% less retained heap** and **2.01% less GC scanning**. - Keeps ordinary eager member resolution. 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 storage migration is consistently applied and directly tested for size, nil behavior, and arena-backed lifetime.

0 open findings

What changed in this PR

Moves rarely used structured-type data into optional arena-backed storage, reducing memory overhead while preserving eager member resolution.

Changes:

  • Adds lazy storage for signatures, index information, and node-builder cache data.
  • Updates checker and node-builder access paths.
  • Adds layout, lifecycle, and accessor tests.
File Description
tsc/​internal/​checker/​types.go Defines compact structured types and optional extra storage.
tsc/​internal/​checker/​checker.go Allocates and accesses structured-type extras lazily.
tsc/​internal/​checker/​relater.go Uses nil-safe structured-type accessors.
tsc/​internal/​checker/​nodebuilderimpl.go Migrates index and node-builder cache access.
tsc/​internal/​checker/​types_test.go Tests layout, allocation stability, and data preservation.

🧠 Review effort: Balanced


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

@jakebailey
Jake Bailey (jakebailey) force-pushed the jakebailey/mem/cold-structured-types branch from e2d42e7 to f681abf Compare October 13, 2026 18:36
Every object, union, and intersection paid for signature and index-info
slice headers, a call-signature count, and a node-builder cache, even
when none were needed. Those fields made StructuredType 144 bytes on
amd64. Keep them in an optional checker-arena sidecar and reduce the
hot record to 88 bytes.

Preserve signature publication during recursive anonymous resolution,
clipped public signature slices, index-info nil/empty distinctions,
and independent node-builder cache identity. Empty unresolved shape
does not allocate a sidecar.

Compared with the parent commit, including all previous checker, AST,
and symbol reductions. Six fresh-process
interleaved samples parse, bind, and check the actual VS Code project
using one checker and normal GC settings.

Live heap falls another 1.81%, GC scan bytes fall 2.01%, and allocated
bytes fall 1.28%. Allocation counts do not differ significantly.
Neither hardware instructions nor elapsed time establishes a change;
this does not claim a CPU improvement.

Exact CLI diagnostic text and compiler counts match the baseline.

Exact benchstat output:

goos: linux
goarch: amd64
pkg: github.com/microsoft/TypeScript/tsc/internal/checker
cpu: Intel(R) Core(TM) i9-10900K CPU @ 3.70GHz
                   │ vscode-shape-before.txt │       vscode-shape.txt       │
                   │         sec/op          │   sec/op     vs base         │
ExternalProgram-20                41.55 ± 6%   41.84 ± 13%  ~ (p=0.937 n=6)

                   │ vscode-shape-before.txt │        vscode-shape.txt        │
                   │       diagnostics       │ diagnostics  vs base           │
ExternalProgram-20                321.0 ± 0%    321.0 ± 0%  ~ (p=1.000 n=6) ¹
¹ all samples are equal

                   │ vscode-shape-before.txt │        vscode-shape.txt        │
                   │          files          │    files     vs base           │
ExternalProgram-20               10.28k ± 0%   10.28k ± 0%  ~ (p=1.000 n=6) ¹
¹ all samples are equal

                   │ vscode-shape-before.txt │          vscode-shape.txt          │
                   │       retained-B        │  retained-B   vs base              │
ExternalProgram-20              3.959Gi ± 0%   3.887Gi ± 0%  -1.81% (p=0.002 n=6)

                   │ vscode-shape-before.txt │          vscode-shape.txt          │
                   │         scan-B          │    scan-B     vs base              │
ExternalProgram-20              3.553Gi ± 0%   3.482Gi ± 0%  -2.01% (p=0.002 n=6)

                   │ vscode-shape-before.txt │        vscode-shape.txt        │
                   │         symbols         │   symbols    vs base           │
ExternalProgram-20               4.154M ± 0%   4.154M ± 0%  ~ (p=1.000 n=6) ��
¹ all samples are equal

                   │ vscode-shape-before.txt │          vscode-shape.txt          │
                   │          B/op           │     B/op      vs base              │
ExternalProgram-20              5.577Gi ± 0%   5.506Gi ± 0%  -1.28% (p=0.002 n=6)

                   │ vscode-shape-before.txt │       vscode-shape.txt       │
                   │        allocs/op        │  allocs/op   vs base         │
ExternalProgram-20               27.36M ± 0%   27.35M ± 0%  ~ (p=0.818 n=6)

                        │ shape-before-instructions.txt │      shape-instructions.txt      │
                        │        instructions/op        │ instructions/op  vs base         │
ExternalInstructions-20                     292.5G ± 4%       301.6G ± 4%  ~ (p=0.093 n=6)
@jakebailey
Jake Bailey (jakebailey) force-pushed the jakebailey/mem/cold-structured-types branch from f681abf to aa8c031 Compare October 13, 2026 20:06
Base automatically changed from jakebailey/mem/cold-symbol-tables to jakebailey/mem/compact-member-indexes October 13, 2026 20:06
@jakebailey
Jake Bailey (jakebailey) deleted the jakebailey/mem/cold-structured-types branch October 13, 2026 20:06
@jakebailey
Jake Bailey (jakebailey) restored the jakebailey/mem/cold-structured-types branch October 13, 2026 20:14
@jakebailey Jake Bailey (jakebailey) added the Domain: Performance Performance related label Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team Domain: Performance Performance related For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

2 participants