Repository navigation
Cache type classification answers on types - #65042
Open
Jake Bailey (jakebailey) wants to merge 5 commits into
Open
Jake Bailey (jakebailey) wants to merge 5 commits into
Jake Bailey (jakebailey) wants to merge 5 commits into
Conversation
resolveStructuredTypeMembers is called on nearly every property, signature and index lookup, and almost always finds the members already resolved. Because the resolution switch lived in the same function, the whole thing was too large to inline, so every lookup paid for a call just to test one flag. Move the resolution switch into a separate worker so the remaining resolved-bit check and cast fit in the inlining budget. To get under the budget, AsStructuredType now only checks the lower bound of the kind range, which is sufficient because intersection is the last type kind. Co-authored-by: Steven Chong <[email protected]>
Type has a byte of padding after its kind. Use it for a small set of internal flags that record answers which never change for a type. shouldNormalizeIntersection is asked repeatedly for the same intersections during relation checking and rescans every constituent each time. Its answer depends only on constituent flags and on whether anonymous constituents are empty, so remember it once those answers are final. Some member resolvers publish empty members before resolution finishes, so a bit now marks types whose members are still being resolved, and the result is not cached while any anonymous constituent is unresolved or mid-resolution. Unions whose constituents are all definitely non-nullable and not instantiable can never produce undefined/null type facts. Record this when the union is created, so that getTypeFacts can skip walking the constituents when the caller only asks about nullability, as it already does for object types. Co-authored-by: Steven Chong <[email protected]>
isWeakType runs for the target of nearly every assignability check against an object type, and each time it re-examines the signatures, index infos and every property of the target, which for large interfaces is a full walk of the member list. The classification is a fixed property of the type once its members are resolved, so remember it in the type's cache flags. The answer is cached only when the members are fully resolved (not published early by an in-progress resolver) and the properties came from the type itself rather than a different apparent type. When getBaseTypes resets partially resolved members of a class or interface, the cached answer is reset along with them. Co-authored-by: Steven Chong <[email protected]>
Every relation cache key computation calls isTypeReferenceWithGenericArguments on both the source and the target, and the check recursively walks all type arguments of nested type references. For deeply nested generic references this repeats the same walk on every relation check involving them. The type arguments of a non-deferred type reference are fixed when it is created, so the answer never changes. Remember it in the type's cache flags so later calls are a flag test. Co-authored-by: Steven Chong <[email protected]>
getSingleBaseForNonAugmentingSubtype is called for every pair of type references during relation checks. Once computed, the common answer is that there is no single equivalent base type, yet each call still did a map lookup to find that out. Set IdenticalBaseTypeExists when a base is actually cached, as Strada does, so a computed reference without one returns immediately and only the positive case consults the map. Co-authored-by: Steven Chong <[email protected]>
Member
Author
|
TypeScript Bot (@typescript-bot) perf test this faster |
Contributor
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The cache changes affect reentrant member resolution, and their lifetime assumptions require compiler regression-suite validation that cannot be run in this review environment.
No open issues 🎉
What changed in this PR
This PR reduces repeated type-classification work in the native TypeScript checker by caching answers directly on types, with safeguards for members that are still being resolved.
Changes:
- Adds compact cache flags within existing
Typepadding. - Caches generic-argument, weak-type, and intersection-normalization checks.
- Adds shortcuts for non-nullable union facts and absent equivalent base types.
| File | Description |
|---|---|
tsc/internal/checker/types.go |
Defines cache flags and simplifies the structured-type kind check. |
tsc/internal/checker/relater.go |
Caches weak-type results when member resolution is final. |
tsc/internal/checker/checker.go |
Implements classification caches, resolution tracking, invalidation, and lookup shortcuts. |
Review effort: Balanced
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.
Thanks Steven (@teamchong) for finding these!