Skip to content

Commit 76d9c3d

Browse files
vanceingallsclaude
andcommitted
perf(engine): scale worker-count caps with cpu count
Follow-up to hf#732 commit 74adf6d. The hybrid layered/shader-blend path saturates well past 6 DOM workers on multi-core hosts, but the engine's `calculateOptimalWorkers` clamped both the explicit `--workers N` request and the `auto` default to a hardcoded ceiling of 10 / 6 respectively. On the 96-core validation host, w=8, w=12, w=16 all collapsed to 6-10 internally, masking whether the wall is algorithmically bound or just cpu-starved by the cap. Two changes: * `ABSOLUTE_MAX_WORKERS`: 10 → 24. Explicit `--workers 16` now surfaces 16 DOM sessions instead of being silently truncated to 10. The new ceiling is still finite because CDP-protocol dispatch serializes through Node's main event loop; past ~24 we expect noise to dominate signal. Holding 24 as a hard cap matches what a thoughtful operator would have picked manually. * `DEFAULT_SAFE_MAX_WORKERS` (a constant) → `defaultSafeMaxWorkers()` returning `Math.max(6, Math.min(16, Math.floor(cpuCount / 8)))`. On 8-core: 6 (unchanged). On 16-core: 6. On 32-core: 6. On 64-core: 8. On 96-core: 12. On 128-core: 16. The /8 divisor leaves headroom for each Chrome worker's SwiftShader compositor + the in-process shader-blend `worker_threads` pool, both of which are themselves CPU-heavy. Hard 16-cap caps the bump so a 256-core host does not spawn enough Chrome processes to OOM the box. Empirical role: This change is intentionally a probe. If the new ceiling moves the shader-render wall meaningfully (108s → lower at w=12), the prior hf#732 fix was cpu-bound at the old cap and the next bottleneck is something else. If the wall stays flat across w=4 → w=16, lever 1 confirms the ceiling is genuinely algorithmic (DOM-capture serialization through Node's main event loop) and lever 2 — the DOM-capture cost itself — is the next attack surface. The CPU-scaled `auto` default also matters for production users on big hosts who never pass `--workers`: they previously left ~90 cores idle on a 96-core machine. Tests: * parallelCoordinator.test.ts: existing 7 tests pass. They cover both the explicit-request path (capped at `ABSOLUTE_MAX_WORKERS`) and the auto path. The auto path with `concurrency: 6` in the test config exercises the explicit branch (`concurrency !== "auto"`), so the new `defaultSafeMaxWorkers()` is reached only through the literal-`"auto"` branch which is covered by the engine's existing default-config integration tests. — Vai Co-Authored-By: Vai <[email protected]>
1 parent 74adf6d commit 76d9c3d

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎packages/engine/src/services/parallelCoordinator.ts‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,23 @@ export interface WorkerSizingConfig extends Partial<
6464

6565
const MEMORY_PER_WORKER_MB = 256;
6666
const MIN_WORKERS = 1;
67-
const ABSOLUTE_MAX_WORKERS = 10;
68-
const DEFAULT_SAFE_MAX_WORKERS = 6;
67+
// Hard ceiling on explicit `--workers N` requests. Above this, the cost of
68+
// CDP-protocol dispatch through Node's main event loop and OS scheduling
69+
// noise overwhelms any further parallelism. Bumped from 10 → 24 in hf#732
70+
// follow-up so high-core hosts (32-96+ cores) can actually surface the
71+
// hardware to renders that are CPU-bound on DOM capture.
72+
const ABSOLUTE_MAX_WORKERS = 24;
73+
// `auto` concurrency picks this many workers as the upper bound. Bumped
74+
// from a hardcoded 6 → CPU-scaled value (floor(cpuCount/8), floor at 6,
75+
// ceiling at 16) in hf#732 follow-up. Rationale: the prior fixed cap of 6
76+
// left ~90 cores idle on the validation host and forced users to pass
77+
// `--workers N` to opt in. Now `auto` matches what a thoughtful operator
78+
// would pick by hand. The /8 divisor leaves headroom for each Chrome
79+
// worker's SwiftShader compositor + the shader-blend thread pool, both of
80+
// which are themselves CPU-heavy.
81+
function defaultSafeMaxWorkers(): number {
82+
return Math.max(6, Math.min(16, Math.floor(cpus().length / 8)));
83+
}
6984
const MIN_FRAMES_PER_WORKER = 30;
7085

7186
export function calculateOptimalWorkers(
@@ -79,7 +94,7 @@ export function calculateOptimalWorkers(
7994
if (concurrency !== "auto") {
8095
return Math.max(MIN_WORKERS, Math.min(ABSOLUTE_MAX_WORKERS, Math.floor(concurrency)));
8196
}
82-
return DEFAULT_SAFE_MAX_WORKERS;
97+
return defaultSafeMaxWorkers();
8398
})();
8499
const effectiveCoresPerWorker = config?.coresPerWorker ?? DEFAULT_CONFIG.coresPerWorker;
85100
const effectiveMinParallelFrames = config?.minParallelFrames ?? DEFAULT_CONFIG.minParallelFrames;

0 commit comments

Comments
 (0)