Repository navigation
Optimize getPropertiesOfUnionOrIntersectionType - #65529
Conversation
|
TypeScript Bot (@typescript-bot) test it |
There was a problem hiding this comment.
🟡 Changes recommended
The selection loop unnecessarily materializes later constituents after finding an empty one, regressing a fast path, and lacks targeted performance and indexed-constituent regression tests.
2 open issues
What changed in this PR
This PR reduces unnecessary union-property resolution in the native TypeScript checker, targeting the large-union type explosion reported in #64692.
Changes:
- Selects the union constituent with the fewest properties and no index signatures as the enumeration representative.
- Adds a property-count helper that avoids materializing property lists for types with lazy layouts.
- Reuses the helper in weak-type and string-index-only checks.
| File | Description |
|---|---|
tsc/internal/checker/relater.go |
Uses the property-count helper when identifying weak types. |
tsc/internal/checker/checker.go |
Optimizes union representative selection and adds the reusable property-count helper. |
Review effort: Balanced
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Hey Anders Hejlsberg (@ahejlsberg), the results of running the DT tests are ready. Everything looks the same! |
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
|
TypeScript Bot (@typescript-bot) perf test this faster |
|
Anders Hejlsberg (@ahejlsberg), the perf run you requested failed. You can check the log here. |
|
Anders Hejlsberg (@ahejlsberg) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Anders Hejlsberg (@ahejlsberg), the perf run you requested failed. You can check the log here. |
|
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: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||


This PR optimizes
getPropertiesOfUnionOrIntersectionTypewhen applied to union types. We now locate the constituent with the fewest properties and no index signatures and use that as the representative for checking properties of the union, as all properties must be present in all constituent types.Fixes #64692.