Skip to content

Commit 3eafea1

Browse files
authored
Merge pull request swiftlang#51 from kastiglione/dl/adjust-batch-partition-count-calculation
Adjust batch partition count calculation
2 parents 4b35f2e + c845905 commit 3eafea1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,23 @@ extension Driver {
302302
// pre-batch-mode 1000. I.e. it's still running 96% fewer
303303
// subprocesses than before. And significantly: it's doing so while
304304
// not exceeding the RAM of a typical 2-core laptop.
305+
306+
// An explanation of why the partition calculation isn't integer
307+
// division. Using an example, a module of 26 files exceeds the
308+
// limit of 25 and must be compiled in 2 batches. Integer division
309+
// yields 26/25 = 1 batch, but a single batch of 26 exceeds the
310+
// limit. The calculation must round up, which can be calculated
311+
// using: `(x + y - 1) / y`
312+
let divideRoundingUp = { num, div in
313+
return (num + div - 1) / div
314+
}
315+
305316
let defaultSizeLimit = 25
306317
let numInputFiles = swiftInputFiles.count
307318
let sizeLimit = info.sizeLimit ?? defaultSizeLimit
308319

309320
let numTasks = numParallelJobs ?? 1
310-
return max(numTasks, numInputFiles / sizeLimit)
321+
return max(numTasks, divideRoundingUp(numInputFiles, sizeLimit))
311322
}
312323

313324
/// Describes the partitions used when batching.

0 commit comments

Comments
 (0)