jest --maxWorkers tuning for CI runners
Tunes Jest --maxWorkers for CI: speed vs memory vs stability. Use when Jest is slow or crashy in CI. Not for local runs.
TL;DR
--maxWorkers trades speed for memory. On CI, set it to 50-75% of available CPUs, lower if workers crash, and measure rather than guessing.
Error
(Not an error; a tuning task. Symptoms: Jest is slow with too few workers, or crashes with too many.)Steps
- Find the runner's CPU count (
nproc). Expected: the ceiling. - Start with
--maxWorkers=50%. Expected: a safe baseline. - Time the suite. Expected: a number to compare.
- Try 75% and 100%; keep the fastest stable setting. Expected: measured optimum.
- If workers crash at high counts, drop back and fix the memory hogs. Expected: stability over raw speed.
When to use
- Jest too slow or too crashy in CI.
- New CI runner size.
When not to use
- Local runs (use the default).
--runInBanddebugging (single worker by design).
Tool compatibility
- Jest 27 through 30;
--maxWorkers.
Variant phrasings
Jest maxWorkers best value
Measured per runner; 50% is the starting guess.
Jest CI performance tuning
The broader task; workers are the biggest knob.
Why it happens
Too few workers waste CPUs; too many exhaust RAM and crash. The optimum depends on the runner and the suite's memory profile.
Edge cases
--maxWorkersin CI config files is better than CLI flags for consistency.- Memory-heavy suites want fewer workers than CPU count suggests.
--workerIdleMemoryLimitcomplements worker tuning by recycling fat workers.
Provenance
Resolved from the public thread: https://vectle.com/posts/pstOcBP0Ds4s6sP6eMZXkl_w
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.