Skip to content

Commit abfa620

Browse files
committed
Fix perf regression from microsoft#42556
PR microsoft#42556 was a nice optimization that dramatically sped up comparisons of discriminated unions. Unfortunately, the cost of determining whether a union is discriminated can be prohibitively high. In particular, an internal team with a very large repo saw their type count double and their memory usage increase from 6GB to 9GB, breaking their build. This changes splits the difference by not trying to compute the property types of intersection types - a notoriously slow operation.
1 parent f7ef154 commit abfa620

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22023,7 +22023,7 @@ namespace ts {
2202322023
// The candidate key property name is the name of the first property with a unit type in one of the
2202422024
// constituent types.
2202522025
const keyPropertyName = forEach(types, t =>
22026-
t.flags & (TypeFlags.Object | TypeFlags.Intersection | TypeFlags.InstantiableNonPrimitive) ?
22026+
t.flags & (TypeFlags.Object | TypeFlags.InstantiableNonPrimitive) ?
2202722027
forEach(getPropertiesOfType(t), p => isUnitType(getTypeOfSymbol(p)) ? p.escapedName : undefined) :
2202822028
undefined);
2202922029
const mapByKeyProperty = keyPropertyName && mapTypesByKeyProperty(types, keyPropertyName);

0 commit comments

Comments
 (0)