From 1944e8ce97c3465606fe3a0e356a158dbe1214fe Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Fri, 19 Apr 2024 10:18:41 -0700 Subject: [PATCH] Improve type-checking time of `listTestsForSwiftPM` Type-checking of the chained return expression took over 10 secs. --- Sources/Testing/Running/EntryPoint.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/Testing/Running/EntryPoint.swift b/Sources/Testing/Running/EntryPoint.swift index db5693ed1..e68c914b5 100644 --- a/Sources/Testing/Running/EntryPoint.swift +++ b/Sources/Testing/Running/EntryPoint.swift @@ -107,12 +107,14 @@ func listTestsForSwiftPM(_ tests: some Sequence) -> [String] { // Group tests by the name components of the tests' IDs. If the name // components of two tests' IDs are ambiguous, present their source locations // to disambiguate. - return Dictionary( + let initialGroups = Dictionary( grouping: tests.lazy.map(\.id), by: \.nameComponents ).values.lazy .map { ($0, isAmbiguous: $0.count > 1) } - .flatMap { testIDs, isAmbiguous in + + // This operation is split to improve type-checking performance. + return initialGroups.flatMap { testIDs, isAmbiguous in testIDs.lazy .map { testID in if !isAmbiguous, testID.sourceLocation != nil {