Skip to main content
Process isolation runs each benchmark in a fresh copy of the benchmark process. It is on by default in the integrations that support it.

Why it makes a difference

When all benchmarks run in the same process, each benchmark inherits the state that the benchmarks and setup code before it leave behind:
  • Allocator state: free lists, fragmentation, and the memory the allocator already holds change how much work each allocation takes.
  • Runtime state: in JIT-compiled runtimes like Node.js, the code that ran before changes which functions are already optimized, and the size of the heap changes when the garbage collector runs.
  • Threads and handles: thread pools, open files, and timers that earlier code started keep running.
A benchmark’s result then depends on the code around it, not only on the code it measures. Adding, removing, or reordering a benchmark can change the result of another benchmark that didn’t change, and CodSpeed reports a regression or improvement that your change didn’t cause. In a fresh process, every benchmark starts from the same state, whatever else your benchmark suite contains.

How it works

The benchmark process runs the benchmarks one after the other. For each benchmark, it starts the same program again, with the same arguments and environment, and the new process measures only that benchmark. The benchmark process waits for it to finish before it starts the next one. As a consequence:
  • Code outside the benchmark functions, e.g., top-level setup, runs once in the benchmark process and again in every benchmark process it starts.
  • Every benchmark pays the startup cost of a new process, so a benchmark suite with many short benchmarks takes longer to run.
  • Benchmarks can’t depend on each other. State that one benchmark leaves behind, e.g., a filled cache, is not there for the next one.
  • A benchmark process that fails, e.g., with a non-zero exit code, fails the run.

Supported integrations

  1. CPU Simulation and Memory measure each benchmark once, so the state that other benchmarks leave behind shows directly in the result. Walltime runs each benchmark many times, which makes it less prone to this variance.
  2. In Node.js, walltime runs each benchmark in several processes, called forks, to measure it across different JIT, allocator, and GC states.
  3. JMH runs each benchmark in separate JVMs, called forks, by default. Set the number of forks with @Fork or -f. CODSPEED_PROCESS_ISOLATION doesn’t apply.

Turning off process isolation

Set the CODSPEED_PROCESS_ISOLATION environment variable to false or 0 in the step that runs your benchmarks to measure all benchmarks in a single process:
.github/workflows/codspeed.yml
Other values than true, 1, false, and 0 fail the run.