Compares the library at a baseline commit (809bcc2, before the #993/#994/#997
perf commits) against HEAD, for three targets:
- cache —
CacheAndBufferLayerhot paths, via an in-memory backend. No docker. - postgres — driver called directly against
postgres:14-alpine(docker). - mongodb — driver called directly against
mongo(docker).
The harness imports the library's .ts source directly (Node ≥24 strips types),
so there is no build step. The before side is a git worktree at the
baseline commit with its own pnpm install.
Everything (needs Docker running):
node benchmarks/run.mjsCache only (no Docker):
BENCH_TARGETS=cache node benchmarks/run.mjsOutput: benchmarks/results.html (self-contained chart) and
benchmarks/results.json (raw merged data).
BENCH_TARGETS— csv subset ofcache,pg,mongo(default all).BENCH_ITERS,BENCH_WARMUP,BENCH_BULK_ROUNDS,BENCH_BULK_BATCH— workload sizes.BEFORE_COMMIT/AFTER_COMMIT— override the compared commits.
node --test benchmarks/lib/stats.test.mjs benchmarks/lib/timing.test.mjs benchmarks/render.test.mjs- cache ops (
set,getHit,getMiss,remove) run with caching enabled butwriteInterval: 0(unbuffered), so each awaited op completes immediately against a trivial in-memoryMapbackend — isolating the cache-layer CPU work (clone-in/out, lock-free get fast path, dirty-keySet). Theflushrow measures flush-rounds/sec: a batch ofbulkBatchkeys is buffered, then a singleflush()that drains them is timed (so ops/sec there is flushes/sec, not key-writes/sec — multiply bybulkBatchfor key throughput). Both sides are measured identically, so the Δ% is apples-to-apples. - postgres / mongodb ops call the driver classes directly (bypassing the
cache layer) so the prepared statements, batched
doBulk, andfindKeysquery paths are actually exercised.
Alongside the one-off before/after harness above, the repo runs vitest bench
in CI to catch regressions over time. The bench files live next to the harness:
benchmarks/cache.bench.ts,benchmarks/postgres.bench.ts,benchmarks/mongodb.bench.ts— measured withvitest bench.
Run locally:
pnpm bench # all targets (PG/Mongo need Docker)
pnpm exec vitest bench --run benchmarks/cache.bench.ts # cache only, no Docker
The benchmark CI job runs pnpm bench:ci (which writes
benchmarks/ci/output.json via benchmarks/ci/to-gab.mjs) and feeds
benchmark-action/github-action-benchmark. On pushes to the default branch it
stores history on the gh-pages branch (a chart-over-time page under
dev/bench); on PRs it compares and comments. A benchmark that drops 1.5x or
more versus the baseline raises an alert. fail-on-alert is off by default —
the job warns rather than failing red, because DB-throughput benches on shared
runners are noisy. The cache benches are the reliable signal.
Note: github-action-benchmark creates and maintains the gh-pages branch and a
published benchmark page on the repository.
The three perf commits are not a uniform speedup — read the chart with that in mind:
- Big wins: postgres
doBulk(+248%, batched multi-row upsert) and cacheflushBigCache(~+1759%, the dirty-key Set letsflush()skip scanning the whole LRU). Postgresget/removegain modestly from prepared statements. - A real regression: cache
getHitis ~58% slower. Commit #993 made the read path return astructuredClone()of the cached value instead of the previous hand-rolled clone — safer (callers can't mutate the cache) but slower per read. This is a deliberate correctness/speed tradeoff, not a harness artifact. The bundled "lock-free get fast path" only pays off under concurrent readers, which this sequential micro-benchmark does not exercise. - Mongo: all ops within ±3% — its changes (anchored
findKeysregex, dropped per-op ping) are correctness/robustness wins that don't move local-container throughput.
Both sides run the identical workload, in the identical op order, each in its own
fresh node process, so the Δ% is apples-to-apples per operation.
The before worktree installs the lockfile as it was at the baseline commit
(e.g. mongodb@7.2.0), while after uses the current lockfile (mongodb@7.3.0).
Reported deltas reflect ueberDB's own changes and any driver-library
minor-version differences. This is the honest "repo then vs now" comparison.