Repository navigation
Add new optimized map types for checker caches / sets - #65812
Open
Jake Bailey (jakebailey) wants to merge 1 commit into
Open
Jake Bailey (jakebailey) wants to merge 1 commit into
Jake Bailey (jakebailey) wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The hash leaves strided type IDs clustered, making named-union processing quadratic, and the generation-cleared set and pool lack focused lifecycle tests.
2 open issues
What changed in this PR
Optimizes compiler checker caches and union construction with specialized hash maps and reusable type-ID sets.
Changes:
- Replaces selected Go maps with open-addressing maps, avoiding redundant hashing of prehashed keys.
- Adds pooled, generation-cleared sets for named-union membership.
- Updates cache access and union iteration for the new containers.
| File | Description |
|---|---|
tsc/internal/checker/types.go |
Changes instantiation-cache field types. |
tsc/internal/checker/types_test.go |
Removes initialization of replaced maps. |
tsc/internal/checker/flow.go |
Uses the new evolving-array cache methods. |
tsc/internal/checker/flatmap.go |
Implements specialized maps and pooled sets. |
tsc/internal/checker/checker.go |
Integrates containers into checker operations. |
Review effort: Balanced
| } | ||
|
|
||
| func hashFlatKey32(k uint32) uint32 { | ||
| return k * flatMapHashMul32 |
Comment on lines
+294
to
+298
| s.count = 0 | ||
| s.gen++ | ||
| if s.gen == 0 { | ||
| clear(s.slots) | ||
| s.gen = 1 |
… scratch sets
Instantiation and cached-type maps previously re-hashed pre-hashed
128-bit CacheHashKeys inside Go maps, and short-lived sets allocated
and cleared Go maps on hot union paths.
Add open-addressing flatTypeMap and flatCachedTypeMap using
CacheHashKey bits directly, and pooled generation-stamped O(1)-clear
clearableU32Set.
benchstat (-pgo=off, parent vs commit, n=6):
goos: linux
goarch: amd64
│ old │ new │
│ sec/op │ sec/op vs base │
Tsc/vscode 6.178 ± 3% 6.015 ± 2% ~ (p=0.093 n=6)
Tsc/mui-docs 3.585 ± 2% 3.434 ± 2% -4.21% (p=0.004 n=6)
geomean 4.706 4.545 -3.43%
│ old │ new │
│ B-rss │ B-rss vs base │
Tsc/vscode 4.513Gi ± 2% 4.501Gi ± 2% ~ (p=0.485 n=6)
Tsc/mui-docs 2.113Gi ± 7% 2.126Gi ± 7% ~ (p=0.937 n=6)
geomean 3.088Gi 3.094Gi +0.20%
Jake Bailey (jakebailey)
force-pushed
the
fast-pr/flat-type-map
branch
from
December 4, 2026 23:12
712b1ad to
e95f63e
Compare
Member
Author
|
TypeScript Bot (@typescript-bot) perf test this faster |
Contributor
Contributor
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This branch has not been deployed
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.

This adds a custom map which can be more efficient and avoid double hashing of
CacheHashKeys, and also something for type ID sets in union type construction (building my last PR for this code).benchstat (-pgo=off, parent vs commit, n=6):