recommendedWorkerCount static method
How many chunks of bytesPerChunk each (typically a plan's own
TiffChunkPlan.bytesPerChunk) can run at once without the aggregate
exceeding aggregateBudgetBytes — the number to pass as a parallel
decoder's worker count when chunk size was chosen independently of
worker count (as forBudget does; see its doc comment for why
shrinking chunks to fit more workers is usually the wrong trade-off).
Also capped at cpuCount (never spawn more workers than there are
cores to run them on) and always at least 1.
Implementation
static int recommendedWorkerCount({
required int bytesPerChunk,
required int aggregateBudgetBytes,
required int cpuCount,
}) {
final memoryCap =
aggregateBudgetBytes ~/ (bytesPerChunk < 1 ? 1 : bytesPerChunk);
final capped = [memoryCap, cpuCount].reduce((a, b) => a < b ? a : b);
return capped < 1 ? 1 : capped;
}