@@ -701,16 +701,17 @@ package struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
701
701
let languageAndTarget = TargetAndLanguage ( target: fileIndexInfo. target, language: fileIndexInfo. language)
702
702
fileIndexInfosToBatch [ languageAndTarget, default: [ ] ] . append ( fileIndexInfo)
703
703
}
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 )
704
708
let batchedPartitions =
705
709
fileIndexInfosToBatch
706
710
. sorted { $0. key < $1. key } // Ensure we get a deterministic partition order
707
711
. 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
+ }
714
715
}
715
716
return partitions + batchedPartitions
716
717
}
0 commit comments