ac-bench
Explanation

Explanation

How a gate decides

A gate turns a benchmark into a check that answers pass, fail or inconclusive. Why it reads executions, works on the log scale, and treats “not settled” as an answer.

A gate turns a benchmark into a check: “new is at most 1.2× three”, “this case is no more than 3 % slower than the recorded baseline”. It is evaluated from the executions a run recorded, and answers pass, fail or inconclusive. This page explains why it decides the way it does.

A gate reads executions, not samples

One execution is one fresh process (or browser) measuring the condition. Samples inside an execution are correlated: they share the process’s memory layout, its JIT decisions, its CPU frequency. Two processes running the same code routinely differ by more than any sample spread inside either — the process lottery.

A gate that pooled every sample as if independent would report an interval far narrower than the truth, and pass or fail on the luck of one process. So the unit of evidence is the execution. Each contributes its estimate and its own within-execution variance, and the gate pools executions with a random-effects model whose between-execution variance is the lottery.

Why the log scale

Durations are ratios at heart: “twice as slow” means the same thing at 2 ns and at 2 s, and noise grows with the value. On the log scale a ratio becomes a difference, a multiplicative spread becomes additive and roughly symmetric, and the interval on log(a/b) maps back to an interval on the ratio that is never negative.

A metric whose differences are absolute (allocated bytes, where 0 B is a meaningful answer) declares the linear scale instead. Each statistic is computed on the scale its metric declares.

Why Hartung–Knapp

With three to nine executions, the between-execution variance is itself poorly estimated. The classical DerSimonian–Laird interval treats it as known: its intervals are too narrow, and too narrow is exactly the failure a gate must not have, since it turns noise into a confident “fail”.

The Hartung–Knapp–Sidik–Jonkman adjustment uses a t distribution on the observed heterogeneity and stays close to its nominal coverage with few executions. It costs width, which the gate pays back by escalating: an undecided gate asks for more executions before it settles for inconclusive. The config’s gate.pooling selects dersimonian-laird instead.

Why Holm

A run declares many gates. At a 5 % error rate each, twenty independent gates fail one by chance on every run. Holm’s step-down procedure controls the family-wise error rate across a run’s gates without assuming they are independent, and it is uniformly more powerful than Bonferroni: the gate with the smallest p-value is tested at α/m, the next at α/(m−1), and so on.

The config’s gate.multiplicity selects bonferroni or none. Holm is the default because a failed gate should mean something on every run, not on most.

Inconclusive is an answer

A gate whose interval straddles its threshold has not passed and has not failed. Calling it either would make the result depend on noise. It exits with its own status, 2, which a CI job can choose to accept with --allow-inconclusive: a decision about noise made once, in the job, rather than hidden in a threshold padded until it never fires.

A gate is part of the run

Reporters render events as they arrive and owe the run nothing. A gate needs every execution of its conditions before it can decide, its advice changes what the run measures next (escalation), and its verdict sets the exit status.

That is why a gate is a pure function of archives rather than a reporter. It evaluates the same way during a run and afterwards (measure gate archive.json), and a baseline is just another archive.

One fresh engine per execution

The reasoning that makes the execution the unit of evidence also makes each one start fresh. A browser kept across executions carries its JIT state and heap from one into the next, and the executions stop being independent draws of the lottery.

browser isolation each execution gets separate renderer process
"browser" (default) a new browser process tree every engine
"context" a new context in a shared browser Chromium

The clock bounds the shortest span

Every runtime’s clock is performance.now(), and its step is coarse in browsers. A timed span covers at least 100 steps, so quantisation adds at most 1/(100·√12) ≈ 0.3 % to a sample; duration calls the case several times per span to reach it (How a case is sampled). Cross-origin isolation, which the browser runtimes’ server provides, is what makes the browser steps fine enough:

runtime isolated not isolated
Node ≈ 27 ns —
Chromium 5 µs 100 µs
Firefox, WebKit 20 µs 1 ms