Skip to content

Latest commit

 

History

History

benchmarks

README.md

ueberDB perf benchmarks (before vs after)

Compares the library at a baseline commit (809bcc2, before the #993/#994/#997 perf commits) against HEAD, for three targets:

  • cache — CacheAndBufferLayer hot 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.

Run

Everything (needs Docker running):

node benchmarks/run.mjs

Cache only (no Docker):

BENCH_TARGETS=cache node benchmarks/run.mjs

Output: benchmarks/results.html (self-contained chart) and benchmarks/results.json (raw merged data).

Knobs (env vars)

  • BENCH_TARGETS — csv subset of cache,pg,mongo (default all).
  • BENCH_ITERS, BENCH_WARMUP, BENCH_BULK_ROUNDS, BENCH_BULK_BATCH — workload sizes.
  • BEFORE_COMMIT / AFTER_COMMIT — override the compared commits.

Unit tests

node --test benchmarks/lib/stats.test.mjs benchmarks/lib/timing.test.mjs benchmarks/render.test.mjs

How each target is measured

  • cache ops (set, getHit, getMiss, remove) run with caching enabled but writeInterval: 0 (unbuffered), so each awaited op completes immediately against a trivial in-memory Map backend — isolating the cache-layer CPU work (clone-in/out, lock-free get fast path, dirty-key Set). The flush row measures flush-rounds/sec: a batch of bulkBatch keys is buffered, then a single flush() that drains them is timed (so ops/sec there is flushes/sec, not key-writes/sec — multiply by bulkBatch for 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, and findKeys query paths are actually exercised.

Permanent CI tracking (vitest bench)

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 with vitest 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.

Reading the results (important)

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 cache flushBigCache (~+1759%, the dirty-key Set lets flush() skip scanning the whole LRU). Postgres get/remove gain modestly from prepared statements.
  • A real regression: cache getHit is ~58% slower. Commit #993 made the read path return a structuredClone() 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 findKeys regex, 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.

Caveat

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.

⌂ Proxy