Skip to content

Commit 32e919c

Browse files
authored
Merge pull request #2302 from ahoppen/multi-file-indexing-batch-size
Match the batch size for multi-file indexing to the driver's batch size
2 parents a155a54 + 05c04de commit 32e919c

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Sources/BuildServerIntegration/BuildSettingsLogger.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ package actor BuildSettingsLogger {
4545
if let uri = uris.only {
4646
header = "Build settings for \(uri.forLogging)"
4747
} else if let firstUri = uris.first {
48-
header = "Build settings for \(firstUri.forLogging) and \(firstUri) and \(uris.count - 1) others"
48+
header = "Build settings for \(firstUri.forLogging) and \(uris.count - 1) others"
4949
} else {
5050
header = "Build settings for empty list"
5151
}

Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -701,16 +701,17 @@ package struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
701701
let languageAndTarget = TargetAndLanguage(target: fileIndexInfo.target, language: fileIndexInfo.language)
702702
fileIndexInfosToBatch[languageAndTarget, default: []].append(fileIndexInfo)
703703
}
704+
// Create one partition per processor core but limit the partition size to 25 primary files. This matches the
705+
// driver's behavior in `numberOfBatchPartitions`
706+
// https://github.com/swiftlang/swift-driver/blob/df3d0796ed5e533d82accd7baac43d15e97b5671/Sources/SwiftDriver/Jobs/Planning.swift#L917-L1022
707+
let partitionSize = max(fileIndexInfosToBatch.count / ProcessInfo.processInfo.activeProcessorCount, 25)
704708
let batchedPartitions =
705709
fileIndexInfosToBatch
706710
.sorted { $0.key < $1.key } // Ensure we get a deterministic partition order
707711
.flatMap { targetAndLanguage, files in
708-
// The batch size of 5 was chosen without too many significant performance measurements because most projects
709-
// currently indexed by SourceKit-LSP are limited by preparation time instead of indexing time and it's thus
710-
// hard to quanify the performance characteristics of different batch sizes. 5 seems like a good trade-off to
711-
// share work between files within the same target without overloading a single job with too many files and
712-
// thus losing parallelism.
713-
files.partition(intoBatchesOfSize: 5).map { (targetAndLanguage.target, targetAndLanguage.language, $0) }
712+
files.partition(intoBatchesOfSize: partitionSize).map {
713+
(targetAndLanguage.target, targetAndLanguage.language, $0)
714+
}
714715
}
715716
return partitions + batchedPartitions
716717
}

0 commit comments

Comments
 (0)