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.
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
- 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.
- In Node.js, walltime runs each benchmark in several processes, called forks, to measure it across different JIT, allocator, and GC states.
- JMH runs each benchmark in separate JVMs, called forks, by default. Set the
number of forks with
@Forkor-f.CODSPEED_PROCESS_ISOLATIONdoesn’t apply.
Turning off process isolation
Set theCODSPEED_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
true, 1, false, and 0 fail the run.