Skip to content

Commit 1ce15a4

Browse files
authored
Fix perf regression from microsoft#42556 (microsoft#43949)
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 96c48b7 commit 1ce15a4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22028,7 +22028,7 @@ namespace ts {
2202822028
// The candidate key property name is the name of the first property with a unit type in one of the
2202922029
// constituent types.
2203022030
const keyPropertyName = forEach(types, t =>
22031-
t.flags & (TypeFlags.Object | TypeFlags.Intersection | TypeFlags.InstantiableNonPrimitive) ?
22031+
t.flags & (TypeFlags.Object | TypeFlags.InstantiableNonPrimitive) ?
2203222032
forEach(getPropertiesOfType(t), p => isUnitType(getTypeOfSymbol(p)) ? p.escapedName : undefined) :
2203322033
undefined);
2203422034
const mapByKeyProperty = keyPropertyName && mapTypesByKeyProperty(types, keyPropertyName);

0 commit comments

Comments
 (0)