@ac-bench/gate
Functions
Classes
Constants
Interfaces
Types
baselineCases(baselines: readonly BenchArchive[]): _ReadonlyObjectDeep<{
caseTitle: string;
conditionTitles: string[];
file: string;
runtime: string;
}, never>[]
Every case the baselines selected: what a subject-less baseline gate covers.
baselineFingerprint(environment: Pick<BenchArchive, "machine" | "runtimes" | "run">): BaselineFingerprint
baselineFingerprintId(environment: Pick<BenchArchive, "machine" | "runtimes" | "run">): string
A short hash of a run’s comparability fields: where its baselines are filed,
so a run finds the baseline of its own environment by name and never one of
another machine, mode, major runtime version or set of runtime flags by
accident. Kernel, governor, memory and runtime minor version are left out:
they are compared with a warning, not required equal.
benchExitCode(summary: RunSummary, options?: {
readonly allowInconclusive?: boolean;
}): BenchExitCode
The exit code of a run. Precedence: 130 > 4 > 3 > 1 > 2 > 5 > 0.
Measurement errors outrank a gate failure because a run with a crashed case
has an incomplete gate set: the reader must fix the run before trusting any
verdict. An error verdict is a measurement error (a subject is missing); an
incomparable one is a usage error (the baseline cannot be used).
caseKeyId(key: CaseKey): string
A case’s identity as a string: a JSON tuple, so no title can imitate a part.
compareEnvironments(current: Environment_, baseline: Environment_, runtime: string): EnvironmentComparison
Whether a baseline’s measurements can be compared directly with this run’s.
Required equal: CPU model, logical cores, architecture, OS, the runtime, its
major version and its flags as normalizeRuntimeFlags reads them (a
browser’s launch switches and V8 flags included), and the mode (or, when the
plan was pinned, the plan). Warned but compared: kernel release, the
runtime’s minor version, CPU governor, memory and available parallelism.
Parameters
runtimeThe runtime id the comparison concerns.
decideGates(tests: readonly GateTest[], options: ResolvedGateOptions): readonly _ReadonlyObjectDeep<{
adjustedPValue: number | null;
degreesOfFreedom: number | null;
dispersion: number | null;
escalatedReplicates: number;
estimate: number | null;
estimator: "paired" | "unpaired" | "single" | null;
executions: number[];
id: string;
interval: {
level: number;
lower: number;
upper: number;
} | null;
kind: "ratio" | "difference" | "bound" | "baseline";
message: string;
metric: {
direction: "lower-is-better" | "higher-is-better";
name: string;
scale: "log" | "linear";
unit: {
scale: number;
symbol: string;
};
};
origin: "suite" | "config" | "cli";
pValue: number | null;
rationale?: string;
reason: "decided" | "interval-contains-threshold" | "multiplicity" | "dispersion-exceeds-limit" | "too-few-executions" | "no-threshold" | "case-failed" | "case-filtered" | "metric-unavailable" | "non-positive-value" | "runtime-unsupported" | "runtime-unavailable" | "baseline-case-missing" | "baseline-environment-mismatch";
runtime: string;
subjects: {
caseTitle: string;
conditionTitles: string[];
file: string;
runtime: string;
}[];
threshold: {
max?: number;
min?: number;
};
verdict: "pass" | "fail" | "inconclusive" | "reported" | "skipped" | "not-applicable" | "error" | "incomparable";
}, never>[]
Decides every test: Holm’s step-down procedure (or the chosen adjustment)
over every hypothesis of the run, then one verdict per test, in order.
A hypothesis is decided when its adjusted p-value is at most 1 − confidence; the verdict reports the interval at that step’s level, so a pass
always sits next to an interval entirely inside the threshold. A gate fails
when any hypothesis is decided on the forbidden side, passes when every one
is decided on the allowed side, and is inconclusive otherwise, or when its
dispersion exceeds the limit whatever its interval says.
effectiveGateDeclarations(declarations: readonly LocatedGateDeclaration[], options: Pick<ArchiveEvaluationOptions, "baselines" | "maxRegression" | "normalizeBy">): LocatedGateDeclaration[]
The declarations a run with baselines evaluates: declarations, each
baseline gate given the default normalizeBy it lacks, plus — when there are
baselines and no declaration is a baseline gate — one baseline gate over
every case (maxRegression its threshold, if any), duplicates removed. What
the run checks before measuring and evaluateArchives evaluates afterwards,
so both instantiate the same gates.
evaluateArchives(archives: readonly BenchArchive[], extra: readonly ConfigGateDeclaration[], options?: ArchiveEvaluationOptions): {
readonly errors: readonly GateReferenceError[];
readonly exitCode: BenchExitCode;
readonly verdicts: readonly _ReadonlyObjectDeep<{
adjustedPValue: number | null;
degreesOfFreedom: number | null;
dispersion: number | null;
escalatedReplicates: number;
estimate: number | null;
estimator: "paired" | "unpaired" | "single" | null;
executions: number[];
id: string;
interval: {
level: number;
lower: number;
upper: number;
} | null;
kind: "ratio" | "difference" | "bound" | "baseline";
message: string;
metric: {
direction: "lower-is-better" | "higher-is-better";
name: string;
scale: "log" | "linear";
unit: {
scale: number;
symbol: string;
};
};
origin: "suite" | "config" | "cli";
pValue: number | null;
rationale?: string;
reason: "decided" | "interval-contains-threshold" | "multiplicity" | "dispersion-exceeds-limit" | "too-few-executions" | "no-threshold" | "case-failed" | "case-filtered" | "metric-unavailable" | "non-positive-value" | "runtime-unsupported" | "runtime-unavailable" | "baseline-case-missing" | "baseline-environment-mismatch";
runtime: string;
subjects: {
caseTitle: string;
conditionTitles: string[];
file: string;
runtime: string;
}[];
threshold: {
max?: number;
min?: number;
};
verdict: "pass" | "fail" | "inconclusive" | "reported" | "skipped" | "not-applicable" | "error" | "incomparable";
}, never>[];
}
Offline: measure gate run-1.json run-2.json run-3.json. Pools the archives
as more executions and re-evaluates every gate they recorded plus extra,
against options.baselines when there are any.
A run and its archive evaluated later give the same verdicts: the online path
calls the same instantiation, test and decision.
The result does not depend on the order of archives or of the baselines:
both pool in run id order. A case is selected when any run selected it; a run
that filtered a case out contributes nothing to it, so the case is judged on
the runs that selected it (failed in all of them is an error, not a skip),
and a case no run selected makes its gates skipped. A baseline gate
compares the environments of the archives that contribute executions to it
only, on either side.
Returns The verdicts, the exit code, and the references that did not resolve
(each makes the exit code 4).
Throws When archives is empty.
Throws On a contradictory declaration.
evidenceFromArchives(archives: readonly BenchArchive[]): EvidenceSource
Builds evidence from archives: one run, several runs pooled as more
executions, or a baseline.
A case is looked up by runtime, file, condition titles and title, so the same
case of two archives is one case with the executions of both. A case key does
not carry the condition’s position, so evidence is refused where it would
merge distinct fork units: two conditions sharing their titles in one file,
or one case at two positions across the pooled archives.
The result does not depend on the order of archives: they are pooled in run
id order. A run whose filter excluded a case contributes nothing to it,
neither executions nor status, so a case is judged on the runs that selected
it, as each of them alone would judge it; a case no run selected has no
evidence. The statuses of the selecting runs merge by precedence: measured
anywhere, else failed, else not-run, else unsupported.
Throws On an ambiguous case, or when two archives share a run id
(the same run replayed is not independent evidence).
formatNumber(value: number): string
Three significant digits, no trailing zeros.
instantiateGates(declarations: readonly LocatedGateDeclaration[], catalog: CaseCatalog, runtimes: readonly string[]): {
readonly errors: readonly GateReferenceError[];
readonly instances: readonly GateInstance[];
}
Resolves declarations against the discovered cases, one instance per leaf
fork unit for a suite declaration and one per match of the first subject for
a config declaration, in each runtime the gate applies to.
A suite gate declared in an outer condition applies to every leaf below it,
resolving its titles inside each leaf. A config reference is matched against
the whole fork-unit path (file, condition titles from the root, case), each
segment a glob; { case } alone names a sibling of the gate’s first subject.
Only the first subject expands: any other reference must name exactly one
case. A config reference matching nothing is an error.
Returns The instances, and one error per reference that does not resolve.
Throws On a contradictory declaration.
needsMoreEvidence(test: GateTest, hypothesesInRun: number, options: ResolvedGateOptions): boolean
Escalation advice for one fork unit’s gate: whether more executions would
move it towards a decision.
True when the gate has too few executions to be decided at all; when its
dispersion exceeds the limit (the “re-run” of a noisy ratio); or when some
hypothesis would still be undecided at the Bonferroni level α / m, the
strictest step Holm can reach, so that meeting it guarantees the final pass
decides the gate. False for a gate that is settled for another reason (an
error, a skip, an unsupported runtime, no threshold) or when escalation is
off. The caller bounds the replicates it buys by the plan’s ceiling.
Parameters
hypothesesInRunHow many hypotheses the whole run holds (m).
normalizeRuntimeFlags(runtime: Pick<RuntimeDescription, "kind" | "flags">): string[]
A runtime’s switches as a baseline comparison reads them:
- A switch and its value given as two arguments (
--max-old-space-size 4096)
become one (--max-old-space-size=4096);
- A browser’s
--js-flags=--a --b becomes one --js-flags=--a per V8 flag,
however many --js-flags carried them;
- In the name of a Node or V8 flag,
_ reads as - (--expose_gc is
--expose-gc), as both read it; a browser’s own switches are kept as
written;
- The switches that change no measurement are left out:
--no-warnings,
--disable-warning, --no-deprecation, --title, and a browser’s
--user-data-dir, --crash-dumps-dir, --remote-debugging-port,
--remote-debugging-pipe, --no-first-run and
--no-default-browser-check;
- A flag proven commutative — single-valued, on an explicit list (
--jitless,
--expose-gc, --max-old-space-size, --[no-]opt, …) — is kept once,
sorted first, when every occurrence of it has one value. Any other flag
keeps its order and its repetitions (--import, --require, --loader,
--env-file, --conditions, …: each occurrence acts, in order), and so
does a commutative one given two values (--max-old-space-size=1 --max-old-space-size=2: the last wins).
Any other difference — a V8 flag such as --jitless or --no-opt, a heap
limit, --expose-gc, a browser switch such as --disable-gpu, the order or
the count of --import — makes two runs incomparable.
resolveGateOptions(options?: GateOptions): ResolvedGateOptions
The one place a default is applied.
Throws On a confidence outside (0, 1), a non-positive
maxDispersion, a minExecutions that is not a positive integer, or an
unknown multiplicity or pooling.
runsOnLogScale(kind: "ratio" | "difference" | "bound" | "baseline", metric: GateMetricDescriptor): boolean
Whether the test runs on ln value (every log metric except a difference).
settleGate(instance: GateInstance, settled: {
readonly message: string;
readonly reason: "decided" | "interval-contains-threshold" | "multiplicity" | "dispersion-exceeds-limit" | "too-few-executions" | "no-threshold" | "case-failed" | "case-filtered" | "metric-unavailable" | "non-positive-value" | "runtime-unsupported" | "runtime-unavailable" | "baseline-case-missing" | "baseline-environment-mismatch";
readonly verdict: "pass" | "fail" | "inconclusive" | "reported" | "skipped" | "not-applicable" | "error" | "incomparable";
}): GateTest
The test of an instance that needs no evidence to decide.
testGate(instance: GateInstance, evidence: EvidenceSource, options: ResolvedGateOptions, baseline?: EvidenceSource): GateTest
Tests one instance against the evidence: pools each subject’s executions,
pairs or does not pair the cases, and turns the pair’s difference into one
p-value per threshold side. Pure and linear in the executions.
A ratio (or a bound) on a "log" metric is computed on ln value; a
difference, and anything on a "linear" metric, on the value itself. Cases
are paired when at least minExecutions processes measured both, unpaired
otherwise; a baseline comparison is always unpaired.
Parameters
baselineRequired for a baseline gate; ignored otherwise.
class GateReferenceError extends Error
A gate names a case that does not resolve to exactly one: unknown, ambiguous
between an inherited and an own case, or a duplicate gate id in one fork
unit.
- new (declaration: LocatedGateDeclaration, reference: unknown, matches: readonly _ReadonlyObjectDeep<{
caseTitle: string;
conditionTitles: string[];
file: string;
runtime: string;
}, never>[], message: string): GateReferenceError
- readonly declaration: LocatedGateDeclaration
- readonly matches: readonly _ReadonlyObjectDeep<{
caseTitle: string;
conditionTitles: string[];
file: string;
runtime: string;
}, never>[]
Zero or more than one, as the message says.
- readonly reference: unknown
What was named: a title, a CaseReference or a gate id.
const BENCH_EXIT_CODES: {
readonly gateFailed: 1;
readonly inconclusive: 2;
readonly interrupted: 130;
readonly measurementError: 3;
readonly nothingRan: 5;
readonly success: 0;
readonly usageError: 4;
}
interface EvidenceSource
- get(key: CaseKey): CaseEvidence | undefined
type ArchiveEvaluationOptions = GateOptions & {
readonly allowForeignBaseline?: boolean;
readonly allowInconclusive?: boolean;
readonly baselines?: readonly BenchArchive[];
readonly maxRegression?: number;
readonly normalizeBy?: CaseReference;
}
type BaselineFingerprint = unknown
What two runs must share for one to be the other’s baseline directly: the
fields compareEnvironments requires equal, in a fixed order.
type BenchExitCode = typeof BENCH_EXIT_CODES[keyof typeof BENCH_EXIT_CODES]
type CaseCatalog = unknown
type CaseEvidence = unknown
Every observation of a case, across executions, runs and archives.
type CatalogCase = unknown
One discovered case, with the fork unit it runs in.
type EnvironmentComparison = unknown
type EnvironmentDifference = unknown
type ExecutionEvidence = unknown
What one execution of a case says about each gate metric.
type GateHypothesis = unknown
One tested comparison: a subject against one bound of one pair.
type GateInstance = unknown
A gate resolved against one runtime’s discovered cases.
type GateOptions = unknown
Run-level knobs of the gate; every statistical one lives in a config file.
type GateReason = z.infer<typeof gateReasonSchema>
type GateTest = unknown
type GateThreshold = ReadonlyDeep<z.infer<typeof gateThresholdSchema>>
type GateVerdict = ReadonlyDeep<z.infer<typeof gateVerdictSchema>>
The decision for one gate instance.
type GateVerdictKind = z.infer<typeof gateVerdictKindSchema>
type LocatedGateDeclaration = ReadonlyDeep<z.infer<typeof locatedGateDeclarationSchema>>
type ResolvedGateOptions = unknown
type RunSummary = unknown