Repository navigation
Avoid recursive closure allocation in hasBaseType - #65807
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 recursive closure is still created and invoked for direct-base matches, leaving the described fast path and non-closure helper unimplemented.
1 open issue
What changed in this PR
This PR targets allocation overhead in the compiler’s hasBaseType inheritance traversal.
Changes:
- Uses a 16-entry buffer for visited types, falling back to a map.
- Replaces
core.Somecalls with explicit traversal loops.
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Optimizes visited-type storage and traversal loops in hasBaseType. |
Review effort: Balanced
| return false | ||
| } | ||
| for _, b := range baseTypes { | ||
| if check(b) { |
Jake Bailey (jakebailey)
force-pushed
the
fast-pr/has-base-type
branch
from
December 4, 2026 23:12
c7a6731 to
c1dda03
Compare
hasBaseType previously allocated a recursive closure on every call.
Check direct base types inline and use a non-allocating helper for
deeper inheritance chains.
benchstat (-pgo=off, parent vs commit, n=6):
goos: linux
goarch: amd64
│ old │ new │
│ sec/op │ sec/op vs base │
Tsc/vscode 6.134 ± 1% 6.138 ± 3% ~ (p=0.818 n=6)
Tsc/mui-docs 3.665 ± 2% 3.728 ± 1% ~ (p=0.065 n=6)
geomean 4.742 4.783 +0.88%
│ old │ new │
│ B-rss │ B-rss vs base │
Tsc/vscode 4.682Gi ± 3% 4.641Gi ± 2% ~ (p=0.818 n=6)
Tsc/mui-docs 2.177Gi ± 9% 2.183Gi ± 9% ~ (p=0.310 n=6)
geomean 3.193Gi 3.183Gi -0.30%
Jake Bailey (jakebailey)
force-pushed
the
fast-pr/has-base-type
branch
from
December 4, 2026 23:24
c1dda03 to
2a04b62
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.

hasBaseTypepreviously allocated a recursive closure on every call. Check direct base types inline and use a non-allocating helper for deeper inheritance chains.