Repository navigation
Inline the common fast-fail of isSimpleTypeRelatedTo - #65038
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
isSimpleTypeRelatedTo is called up to twice for nearly every relation check, and in the overwhelmingly common case (relating two structured or instantiable types where the target is not a union) it walks a long list of primitive flag tests only to return false. The function was far too large to inline, so each of those checks also paid for a call. Split it into a small wrapper that fits the inlining budget and rejects that case directly, and a worker holding the full logic. The worker additionally short-circuits two cases whose outcome is already decided by a couple of flag tests: two enum members of the same kind, and two structured or instantiable types (where only the unknown-like union check can apply). Results are unchanged. Co-authored-by: Steven Chong <25894545+teamchong@users.noreply.github.com>
Member
Author
|
TypeScript Bot (@typescript-bot) perf test this faster |
Contributor
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified in the type-relation fast-path refactor.
No open issues 🎉
What changed in this PR
Optimizes the native compiler’s type-relation checks by moving the common fast-fail path into a small, inlineable wrapper, while preserving the existing relation logic.
Changes:
- Splits
isSimpleTypeRelatedTointo a wrapper and a worker. - Adds early exits for matching-kind enum members and structured or instantiable types.
| File | Description |
|---|---|
tsc/internal/checker/relater.go |
Adds fast paths to reduce function-call overhead and unnecessary primitive flag checks. |
Review effort: Balanced
Contributor
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ryan Cavanaugh (RyanCavanaugh)
approved these changes
Oct 30, 2026
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.
isSimpleTypeRelatedTo is called up to twice for nearly every relation check, and in the overwhelmingly common case (relating two structured or instantiable types where the target is not a union) it walks a long list of primitive flag tests only to return false. The function was far too large to inline, so each of those checks also paid for a call.
Split it into a small wrapper that fits the inlining budget and rejects that case directly, and a worker holding the full logic. The worker additionally short-circuits two cases whose outcome is already decided by a couple of flag tests: two enum members of the same kind, and two structured or instantiable types (where only the unknown-like union check can apply). Results are unchanged.
Thanks Steven (@teamchong) for finding this!