Repository navigation
Speed up property and index signature lookups - #65043
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
Both functions are called on nearly every property, signature, and index lookup, and the overwhelmingly common input is a plain object type, for which both return the type unchanged. They were only able to reach that answer after a chain of flag tests (and, for getApparentType, a non-inlinable call), and getReducedApparentType paid for it three times. Split each into a small inlinable wrapper that returns early for types that cannot change (non-mapped object types for the apparent type, anything other than a union or intersection for reduction), and let getReducedApparentType skip all three steps for non-mapped object types. Co-authored-by: Steven Chong <[email protected]>
getApplicableIndexInfoForName runs for every property name that is missing from a union constituent, and most types have no index signatures at all. It still created (and interned) a string literal type for the name before discovering there was nothing to match. Check for index infos first. findApplicableIndexInfo also allocated an 8-element slice on every call to collect applicable infos, although at most one is applicable in almost all cases. Track the first applicable info directly and only collect value types once a second one is found. Co-authored-by: Steven Chong <[email protected]>
Synthesizing a union or intersection property looks the name up in every constituent. Constituents are most often object types whose members are already resolved, where the lookup amounts to a single member table probe, yet each one went through getApparentType and the general getPropertyOfTypeEx path (reduced apparent type, member resolution, module and value checks) first. For such constituents, read the member directly when it is a plain value, or when it is missing and Object/Function augmentation is not requested. All other cases (module types, aliases, missing members that may come from the global Object or Function types) still take the full lookup, so the resulting property is unchanged. Co-authored-by: Steven Chong <[email protected]>
getTypeOfPropertyOfContextualType runs for every property of every contextually typed object literal. It passed a closure to mapTypeEx even though the contextual type is usually not a union, so the closure was allocated only to be called once. Handle non-union types directly and keep mapTypeEx for unions. Also, as with getApplicableIndexInfoForName, don't create a string literal type for the property name when the contextual type has no index signatures that it could be matched against. Co-authored-by: Steven Chong <[email protected]>
Resolving the members of a derived class's constructor type cloned the class's exports table so that static members of the base constructor could be added to it. But the base constructor's properties are often all shadowed: every class has its own 'prototype', and many bases have no other statics. In that case the clone was identical to the original and the members were stored a second time for nothing. Find the first base property that would actually be inherited and only clone the table (and reset the type's members) when there is one. The base constructor's properties are still resolved at the same point, so resolution order is unchanged. 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.
🟢 Approval recommended
No active review issues are identified for the checker lookup optimizations.
No open issues 🎉
What changed in this PR
This PR optimizes property and index-signature lookups in the native TypeScript checker by reducing common-path work and allocations.
Changes:
- Adds fast paths for resolved object members, apparent types, and type reduction.
- Avoids unnecessary literal-type creation and allocations during index-signature and contextual-property lookups.
- Skips cloning static member tables when no base members need to be inherited.
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Optimizes checker lookups with fast paths, deferred allocations, and conditional member-table cloning. |
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!