onrails logoonrails
Comparisons

Benchmarks

Microbenchmarks of @onrails/result vs neverthrow and @onrails/pattern vs ts-pattern — method, limits, and a snapshot.

Microbenchmarks live in the private @onrails/bench package. They measure overlapping call shapes only. They are not application profiles.

Full tables and regenerate instructions: packages/bench/RESULTS.md.

Method

  • Runtime: mitata on Bun; sink via do_not_optimize. Suites cover construct, map / flatMap depth, fold, combine, a short async chain, and shallow pattern match (rebuild and hoisted).
  • Bundle: minify + gzip of a fixed import graph (not whole-package weight).
  • Lanes: Result headline is core @onrails/result vs neverthrow. The neverthrow-compat shim is measured separately as migration cost. Pattern compares shallow .with / when / matchTag only — no P.select or deep wildcards (not in @onrails/pattern v1).
  • Versions are pinned in packages/bench/package.json and recorded in the snapshot header.

Reproduce:

bun run build
bun run bench:md

Limits

  • One machine per snapshot (see RESULTS.md environment). Numbers move across CPUs and Bun versions.
  • Nanosecond ops do not predict I/O-bound or allocation-heavy app paths.
  • Ok-path chains only for sync Result transforms (no mixed Err short-circuit mix).
  • Pattern “rebuild” builds the matcher every call; “hoisted” builds once via curried match<T>()…exhaustive(). Both are real usage; do not cite one without the other.
  • Soft CI runs the harness for crashes only — it does not fail when a rival is faster.

Snapshot (illustrative)

From the committed RESULTS.md (Bun 1.4.2, darwin/arm64, @onrails/result 0.4.2, @onrails/pattern 0.3.5, neverthrow 8.2.0, ts-pattern 5.9.0). Prefer the file over this page if they disagree.

Bundle (minify+gzip of fair import graphs)

Import graphminify+gzip
@onrails/result (ok/map/flatMap/match/combine)1,080 B
neverthrow (same surface)2,030 B
@onrails/pattern (match/when/matchTag)827 B
ts-pattern (same surface)2,805 B

Result runtime (avg)

Case@onrails/resultneverthrow
ok4.1 ns2.6 ns
map ×2083 ns76 ns
flatMap / andThen ×20108 ns74 ns
combine ×1663 ns101 ns
short ResultAsync chain291 ns412 ns

Sync map is near parity. neverthrow is ahead on deep andThen. onrails is ahead on combine and the short async chain in this run. Prefer core carriers over the compat shim on hot paths after migration.

Pattern runtime (avg)

Case@onrails/patternts-pattern
disc4 first (rebuild)92 ns64 ns
disc4 first (hoisted)5.2 ns—
disc4 last (rebuild)76 ns146 ns
literal (rebuild)48 ns56 ns
when22 ns74 ns
matchTag (Ok)4.7 ns58 ns

ts-pattern wins first-branch rebuild in this run. Mid/last discriminant, literal, when, and especially matchTag favor onrails. Hoisted matchers remove builder cost; use curried match<T>() when the same match runs often.

Reading the numbers

  • Lead with import-graph size and API fit, not blanket “faster than X”.
  • For _tag ADTs, prefer matchTag over a general match builder.
  • Compat exists for migration; it is not the performance baseline.

On this page