Skip to content

perf: add benches for Option, ResultAsync, and Records#9

Merged
kelsos merged 1 commit intomainfrom
perf/bench-option-recordsasync
Apr 18, 2026
Merged

perf: add benches for Option, ResultAsync, and Records#9
kelsos merged 1 commit intomainfrom
perf/bench-option-recordsasync

Conversation

@kelsos
Copy link
Copy Markdown
Owner

@kelsos kelsos commented Apr 18, 2026

Summary

Round out CodSpeed coverage so every non-trivial namespace has benchmarks tracking it. Previously only `pipe`, `Arrays`, and `Result` were instrumented; this PR adds Option, ResultAsync, and Records.

New bench files

File Covers
`option/transform.bench.ts` map / flatMap / filter across some vs none paths; 5-deep flatMap pipelines for both happy and short-circuit
`result-async/transform.bench.ts` map / flatMap across ok vs err; 5-deep ResultAsync.map chain compared head-to-head with a bare Promise.then chain
`records/transform.bench.ts` mapValues vs handwritten reduce (small + medium), filter at three selectivity regimes, mapKeys rename
`records/access.bench.ts` get/getOr hit vs miss, keys/values/entries vs native Object.*

Why these benches

  • ResultAsync.map vs Promise.then — direct overhead measurement. If the ResultAsync wrapper grows slower than plain promises for ok-path chains, CodSpeed will flag it.
  • Records.mapValues vs handwritten — same for the Records namespace. The handwritten baseline is what users would write without the library.
  • get/getOr vs native access — Records wraps native lookups with an Option/hasOwn check. The benches let us see the cost.
  • Option.map short-circuit — we want to confirm the none-path stays on the fast path.

No API changes

Purely bench additions. All 224 tests still pass, typecheck clean, TypeDoc regenerates clean.

First baseline

The CodSpeed CI run on this PR establishes the first baseline for these 4 files. Future PRs that touch Option/ResultAsync/Records hot paths will automatically get a per-bench regression comment.

Test plan

  • All required CI checks pass
  • CodSpeed runs the new benches and posts comparison results (first baseline for the added files)
  • No regression vs main on the existing pipe/Arrays/Result benches

Round out CodSpeed coverage so every non-trivial namespace has
benchmarks tracking it — previously only pipe, Arrays, and Result were
instrumented.

Added:
- option/transform.bench.ts — map / flatMap / filter across some vs
  none paths; 5-deep flatMap pipelines for both happy and short-circuit.
- result-async/transform.bench.ts — map / flatMap across ok vs err;
  5-deep ResultAsync.map chain compared head-to-head with a bare
  Promise.then chain so regressions in the async overhead show up.
- records/transform.bench.ts — mapValues vs handwritten reduce (small
  + medium), filter under three selectivity regimes, mapKeys rename.
- records/access.bench.ts — get/getOr hit vs miss, keys/values/entries
  vs native Object.*.

No public-API changes. Every bench file uses realistic data shapes
(user ids, per-user aggregates) instead of foo/bar placeholders.

Local results are illustrative only; the CodSpeed CI run on this PR
establishes the first baseline for these namespaces. Future PRs that
change hot paths in any of them will automatically get a per-bench
regression comment on the PR.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.41%. Comparing base (25bae7a) to head (a4b6d4f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main       #9   +/-   ##
=======================================
  Coverage   88.41%   88.41%           
=======================================
  Files          23       23           
  Lines         397      397           
  Branches       90       90           
=======================================
  Hits          351      351           
  Misses         15       15           
  Partials       31       31           
Flag Coverage Δ
unittests 88.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 18, 2026

Merging this PR will not alter performance

✅ 20 untouched benchmarks
🆕 28 new benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 native property access N/A 11.9 µs N/A
🆕 Records.entries N/A 123 µs N/A
🆕 Promise.then chain (5 deep) N/A 21 µs N/A
🆕 Object.keys native N/A 24.4 µs N/A
🆕 ResultAsync.map chain (5 deep, all ok) N/A 31.8 µs N/A
🆕 Records.keys N/A 25.9 µs N/A
🆕 flatMap 5 deep, ok path N/A 34.1 µs N/A
🆕 keep none N/A 391.6 µs N/A
🆕 map over err (short-circuit) N/A 57.8 µs N/A
🆕 Records.mapValues (medium) N/A 1.5 ms N/A
🆕 Records.mapValues (small) N/A 28.5 µs N/A
🆕 map over ok N/A 32.6 µs N/A
🆕 rename prefix N/A 2.1 ms N/A
🆕 handwritten reduce (medium) N/A 1.2 ms N/A
🆕 keep all N/A 1.5 ms N/A
🆕 flatMap 5 deep, early none N/A 17.6 µs N/A
🆕 keep roughly half N/A 577.8 µs N/A
🆕 flatMap 5 deep, some path N/A 18.8 µs N/A
🆕 filter predicate passes N/A 14 µs N/A
🆕 Records.values N/A 78.2 µs N/A
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.


Comparing perf/bench-option-recordsasync (a4b6d4f) with main (25bae7a)

Open in CodSpeed

@kelsos kelsos merged commit a4b6d4f into main Apr 18, 2026
11 checks passed
@kelsos kelsos deleted the perf/bench-option-recordsasync branch April 18, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant