From abfa6200c1605150fa7ed2120200568266b6e87d Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Tue, 4 May 2021 11:00:00 -0700 Subject: [PATCH] Fix perf regression from #42556 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. --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4d95f128b1a0d..4a3f31bcd27c5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22023,7 +22023,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);