Fix perf regression from #42556 (#43949)

PR #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.
This commit is contained in:
Andrew Casey
2021-05-06 17:06:38 -07:00
committed by GitHub
parent 96c48b746a
commit 1ce15a4531

View File

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