verax · benchmarks

verax · bench/run.ts

How fast verax checks data, how that is measured, and every change measured on 2026-11-23: the one kept, the ones dropped and the ones still open.

Run

From the repo root, under the pinned runtimes. Without --base it measures the working copy alone; with it, a second copy of src against the working copy.

mise x -C . -- bun packages/verax/bench/run.ts
mise x -C . -- node packages/verax/bench/run.ts --filter list --time 3000
mise x -C . -- bun packages/verax/bench/run.ts --base /tmp/base/packages/verax/src --json out.json
flag effect
--base <dir> A/B against the copy whose index.ts is in the dir
--filter <text> only cases whose name contains the text
--json <path> also write the rows as JSON, the format of the files under bench/results
--time <ms> sampling budget per case, all processes together; default 1000

A case is group.verb.input: eleven schema groups, each through is, parse and validate on a valid and an invalid input, 66 in all. The columns, in nanoseconds per call:

column meaning
base · work interquartile mean of the per-process means, for each copy
ns/op the same, with no base
min the fastest single sample of the working copy
Δ work / base − 1; negative is faster
± twice the standard error (of the ratio, in A/B): a Δ inside it is noise, and a later run outside it differs

Method

A fresh process per sample

Each process loads one copy of verax, builds every case, and times one: three 2 ms slices to warm, then twelve measured. Processes alternate between the two copies and swap which goes first each round, so drift lands on both. Two copies in one process measured apart on identical code, the later-compiled slower (the run.ts header records up to 35 %), and a process lands a case in one of a few JIT modes, so more time buys more processes, not longer ones: 42 per side and case at --time 2000.

Every schema warmed through every verb

A real program holds many schemas, so the engine sees many shapes at each call site. Before timing, every schema runs is, validate and parse twenty times on both inputs, beside lists and records of five more leaves. Without that, a case measured alone flatters itself: a 1 000-item list(int()) ran is in 287 ns on bun and 262 ns on node as the only list schema, and in 1 530 and 4 189 ns once five others had run (probe, 2026-11-23). Adding the warm-up moved list-int, ns per call:

runtime is.valid parse.valid validate.invalid
bun 2 314 → 2 039 894 → 2 696 4 832 → 6 202
node 4 430 → 4 366 1 138 → 6 753 4 653 → 13 642

Noise

A copy measured against itself on bun, before the warm-up was added, put 4 of 66 rows outside ±, about what twice the standard error predicts; its largest Δ, 8.4 %, sat inside its own ± of 8.6 %. A change is kept only when its Δ clears ± on both runtimes and no other row regresses beyond ±; a borderline row is rerun, never accepted from one run.

Result

Kept: each built-in leaf (boolean, float, int, string and id) walks a list in its own loop with its check inline. Every list schema used to share one loop, so its per-item call site went megamorphic once a program held a few list schemas. Custom scalars, enums, literals and wrapped leaves keep the shared loop.

The A/B below is the source on main before the bench (7bbcd0a) against the merged verax-publish branch, --time 2000, bun 1.4.4 and node 24, one Apple-silicon Mac, 2026-11-23. Lists of scalars run 31–71 % faster on bun and 46–81 % on node (node list-int.is.valid 4 327 → 834 ns). Every other row is within −2.5 % to +3.3 %; the worst slowdown is coerce.is.valid, +1.9 % on bun and +3.3 % on node.

Δ per case, bun and node. faster beyond ± · slower beyond ± · within ±, the shaded band. Hover or tab to a bar for base → work.

Two choices inside the kept change were measured too. Sharing one Int and one Float test function between the loops made bun recursive.validate.invalid 3.8–4.9 % slower in repeated runs, so each leaf keeps its own. The rejection path sizes its output array up front for the leaf loops only: growing it cut node's list-int.validate.invalid gain from −68.0 % to −51.2 %, and sizing it for lists of non-leaf items cost node coerce.validate.invalid +2.0 %.

Tried and dropped

Measured 2026-11-23 against the warmed harness. Probe figures time a 1 000-item list(int()) after five other list schemas ran, or a six-field object.

change measured, ns or Δ why dropped
a switch on leaf kind inside the shared list loop probe is: bun 1 530 → 2 311, node 4 189 → 2 502; the per-leaf loops in the same probe: bun 2 103 → 566, node 4 339 → 976 bun 51 % slower; per-leaf loops win on both runtimes
the same switch for object fields node flat valid rows −5.1 to −7.4 %; bun reordered.is.valid +2.4 % (± 0.9), every nested row +0.6 to +1.1 % bun regresses beyond ±
record output built on a null prototype, the prototype set once at the end bun parse of a 3-key record 28 → 39; 100 keys 715 → 725 (bun only) slower
a schema's checks found through a hidden symbol, not the WeakMap flat object is.valid: bun 75.4 → 76.9, node 135.5 → 126.1; validate.valid: bun 93.0 → 91.5, node 197.6 → 185.1 at most 12 ns, and a foreign schema could forge the symbol
read a field before calling Object.hasOwn not built guarding against a prototype polluted after the plan was built still needs hasOwn on every present value, so valid data saves nothing
enums as a Set not pursued the bench's enums have two values, where includes wins

Lint rewrites rejected for speed

The lint pass of 2026-11-23 rewrote src to satisfy rules and kept only what the A/B showed neutral. Each rule left off for speed says why in oxlint.config.ts.

rewrite measured rule left off
verify as a bound arrow bun parse and validate up to +2.6 % (nested, record, tagged) func-style in core.ts
a record's leaf test through a helper record parse and validate +2.0–2.6 % on bun, +3.1–3.5 % on node no-nested-ternary in types.ts
Number.isSafeInteger for Int a valid Int list's is 55–72 % slower (2026-10-22; raw run not kept) prefer-number-is-safe-integer
iterator helpers in place of index loops values().every over 100 items: bun 2.8×, node 28.4× an index loop (probe) held by the HOT PATH rule in AGENTS.md

Both rewrites rode the lint pass's first batch, measured against b6df244 with the style changes beside them; after reverting the two, a rerun on bun was neutral but for three rows at +0.8 to +1.3 %.

Tuple

Adding tuple left the 66 existing cases where they were: against the source before it, the mean Δ is +0.07 % on bun and −0.22 % on node, and the few rows past ± go both ways, within what noise gives across 66 cases. Default --time, bun 1.4.5 and node 24, 2026-11-25.

Its own groups: tuple holds the six leaves of flat by position, and validates in about a third of the time — bun is 24 ns and parse 34 ns against 70 and 93, node 43 and 67 against 133 and 203. tuple-rows is a list of 100 [id, [float, float]]: bun 1.8 µs is, 2.7 µs parse; node 3.3 and 4.9.

Open options

Code generation

A scratch prototype generated the six-field flat object's is with fixed-key reads and inline leaf checks: bun 77.9 → 41.3 ns valid and 21.9 → 9.2 invalid, node 131.9 → 82.3 and 48.9 → 32.9; validate, not generated, did not move. About 1.6–1.9× on is. The cost: it needs new Function, which a Content Security Policy without 'unsafe-eval' blocks, so it would need the current engine as a fallback. Not implemented; an architecture decision.

A stack trace that starts at the caller

Built and removed: Error.captureStackTrace(error, verb) on the failure path of parse and assert, so a failed assertion points at the test. Plain, it made every failed parse 10–75 % slower on node and up to 28.5 % on bun. Capturing once under Error.stackTraceLimit = 0 brought it to about +80 ns on bun and +200 ns on node (+16 % on the cheapest schemas), but it assigns a global property: under a frozen Error, parse and assert threw TypeError: Attempted to assign to readonly property in place of the VeraxError. Values from the printed tables, rounded.

Add a case, compare a change

A case group is one entry in groups inside cases(): a name, a schema built from the copy being measured, a valid input and an input that fails only at its end. It yields six cases and joins the warm-up by itself; the harness throws if the valid input fails or the invalid one passes. To measure a change, snapshot the source before it and A/B on both runtimes:

git archive <sha> packages/verax/src | tar -x -C /tmp/base
mise x -C . -- bun packages/verax/bench/run.ts --base /tmp/base/packages/verax/src --time 3000
mise x -C . -- node packages/verax/bench/run.ts --base /tmp/base/packages/verax/src --time 3000

Keep a perf change with its before/after run: write it with --json to bench/results/<date>-<change>-<runtime>.json and add it here.