@@ -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