Repository navigation
Speed up property and index signature lookups - #65043
Conversation
|
TypeScript Bot (@typescript-bot) perf test this faster |
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
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
FWIW this looks way better if you view each commit without whitespace, or at least the whole thing https://github.com/microsoft/TypeScript/pull/65043/changes?w=1 |
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 <25894545+teamchong@users.noreply.github.com>
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 <25894545+teamchong@users.noreply.github.com>
b1d92bf to
808320f
Compare
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 <25894545+teamchong@users.noreply.github.com>
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 <25894545+teamchong@users.noreply.github.com>
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 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 <25894545+teamchong@users.noreply.github.com>
808320f to
b1dd849
Compare
|
TypeScript Bot (@typescript-bot) perf test this faster |
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
TypeScript Bot (@typescript-bot) perf test this faster |
|
Starting jobs; this comment will be updated as builds start and complete.
|
|
TypeScript Bot (@typescript-bot) perf test this faster |
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Thanks Steven (@teamchong) for finding these!
FWIW this looks way better if you view each commit without whitespace, or at least the whole thing https://github.com/microsoft/TypeScript/pull/65043/changes?w=1