Skip to content

Compact type mappers and coallocate inference mapper storage - #64796

Merged
Anders Hejlsberg (ahejlsberg) merged 2 commits into
jakebailey/mem/normalization-scratchfrom
jakebailey/mem/compact-type-mappers
Oct 14, 2026
Merged

Anders Hejlsberg (ahejlsberg) merged 2 commits into
jakebailey/mem/normalization-scratchfrom
jakebailey/mem/compact-type-mappers

Conversation

@jakebailey

Copy link
Copy Markdown
Member

Every mapper carries a self-referential interface, and each inference context separately allocates two mappers with the same lifetime.

  • Replaces mapper interfaces with a concrete kind header and places an inference context's two mappers in one allocation.
  • The fixture used 3.90% fewer allocations; VS Code allocations fell 28.52M → 27.17M.
  • Retained heap was effectively unchanged.

Part of the memory optimization stack summarized in #64734.

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

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 compact representation preserves existing behavior and has targeted coverage for its unsafe layout and lifetime invariants.

0 open findings

What changed in this PR

Compacts type mapper dispatch and coallocates inference mappers to reduce compiler allocations.

Changes:

  • Replaces interface-backed mappers with kind-based concrete dispatch.
  • Embeds both inference mappers in their context.
  • Adds behavior, layout, lifetime, and allocation tests.
File Description
tsc/​internal/​checker/​mapper.go Implements compact mapper dispatch.
tsc/​internal/​checker/​inference.go Initializes embedded inference mappers.
tsc/​internal/​checker/​checker.go Adds coallocated mapper storage.
tsc/​internal/​checker/​utilities.go Updates concrete mapper casts.
tsc/​internal/​checker/​types_test.go Tests dispatch, layout, and allocations.

🧠 Review effort: Balanced


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

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.

We be nice to only have one kind type.

Comment thread tsc/internal/checker/mapper.go Outdated
@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) force-pushed the jakebailey/mem/compact-type-mappers branch from 837e1b7 to 8f868f9 Compare October 14, 2026 01:07
Every mapper currently carries a self-referential interface, and each
inference context separately allocates two mappers with the same
lifetime. A concrete kind header eliminates the interface and lets
inference contexts own their fixing and non-fixing mappers in one
allocation.

Fresh parse, bind, and check versus reusable normalization workspaces:

                     │ before │             after              │
                     │  B/op  │    B/op       vs base          │
CheckFreshProgram-20 277.2Mi    276.0Mi      -0.44% (p=0.002 n=6)

                     │ before │             after              │
                     │ allocs/op │ allocs/op   vs base         │
CheckFreshProgram-20   1.139M       1.094M    -3.90% (p=0.002 n=6)

VS Code allocations decrease from 28.52M to 27.17M with identical
compiler counts and diagnostics. Retained memory is effectively
unchanged. Three interleaved fixture runs show fewer fixed-work
instructions, but a single VS Code run is noisy; no wall-time claim is
made.
Keeping a public kind enum next to the private header tag meant two
parallel kind types and a translation switch between them. Exposing the
tag itself gives callers every mapper kind directly. Mapper comparison
still only orders simple, array, and merged mappers, so type ordering
is unchanged.
@ahejlsberg
Anders Hejlsberg (ahejlsberg) added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit 3c105e1 Oct 14, 2026
54 checks passed
@ahejlsberg
Anders Hejlsberg (ahejlsberg) deleted the jakebailey/mem/compact-type-mappers branch October 14, 2026 14:13
@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