From 1ce15a4531584e5a677eb8b0f446460af646d7ca Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Thu, 6 May 2021 17:06:38 -0700 Subject: [PATCH] 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. --- 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 c9cb3fd2854..026a9d7bc90 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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);