Skip to content

Commit

Permalink
Improve perf of unions with many primitives (#45220)
Browse files Browse the repository at this point in the history
  • Loading branch information
ypresto authored Oct 12, 2021
1 parent 44deb84 commit 9e2fc16
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22652,8 +22652,9 @@ namespace ts {
// constituent types keyed by the literal types of the property by that name in each constituent type.
function getKeyPropertyName(unionType: UnionType): __String | undefined {
const types = unionType.types;
// We only construct maps for large unions with non-primitive constituents.
if (types.length < 10 || getObjectFlags(unionType) & ObjectFlags.PrimitiveUnion) {
// We only construct maps for unions with many non-primitive constituents.
if (types.length < 10 || getObjectFlags(unionType) & ObjectFlags.PrimitiveUnion ||
countWhere(types, t => !!(t.flags & (TypeFlags.Object | TypeFlags.InstantiableNonPrimitive))) < 10) {
return undefined;
}
if (unionType.keyPropertyName === undefined) {
Expand Down

0 comments on commit 9e2fc16

Please sign in to comment.