Skip to content

feat(benchmarking): add @sourceloop/benchmarking package - #2613

Merged
a-ganguly merged 3 commits into
masterfrom
feat/benchmarking-package
Oct 1, 2026
Merged

a-ganguly merged 3 commits into
masterfrom
feat/benchmarking-package

Conversation

@sf-sahil-jassal

Copy link
Copy Markdown
Contributor

Description

Adds @sourceloop/benchmarking, a package that lets a team write throughput benchmarks as Mocha tests and fail the build when a change makes an operation slower.

bench.describe() and bench.it() wrap tinybench. Each run records its throughput mean in a committed JSON file. The gate compares the current run against the average of the last ten runs and fails the test when the drop is larger than the threshold.

Two rules differ from what bencher, github-action-benchmark and CodSpeed do, and the README says so plainly:

  • A regressed run is not added to the history. The window holds until the regression is fixed or accepted, so three merges that each lose 15 percent cannot walk the baseline down past a 40 percent gate one step at a time.
  • A new benchmark records samples quietly until it has enough of them. Comparing against a single prior run is a coin flip, not a signal.

The package is ported from an internal perf-testing package that is already in use. Behaviour matches it, except for the renamed environment variables (PERF_* to BENCH_*), the renamed helpers (pit/pdescribe to bench.it/bench.describe), the new minimum sample count, and stricter parsing of numeric settings.

Documentation lives in packages/benchmarking/README.md. Besides the settings table and the rules the gate applies, it covers how to write a benchmark that means something: good and bad examples side by side, why a Promise.all body reports batches per second and not requests per second, and where the noise in a measurement comes from.

Fixes # (issue)

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • 64 unit tests over the config getters, the reporter, the metric conversion and the Mocha helper
  • An acceptance benchmark that runs the package against itself end to end and asserts the sample it recorded
  • npm run build, npm run test and npm run lint in the package, all clean

Reproduce with:

npm run build --workspace @sourceloop/benchmarking
npm run test --workspace @sourceloop/benchmarking
npm run lint --workspace @sourceloop/benchmarking
CI=true npm run test:benchmark --workspace @sourceloop/benchmarking

Note that engines.node is ^22.12.0 || >=24 for this package, not the usual 22 || 24. tinybench 5 is ESM only, and require(esm) is stable from Node 22.12 onwards. The README explains this.

Checklist:

  • Performed a self-review of my own code
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Any dependent changes have been merged and published in downstream modules

@sf-sahil-jassal
sf-sahil-jassal requested a review from a team as a code owner September 22, 2026 13:02
Copilot AI lite review requested due to automatic review settings September 22, 2026 13:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sf-sahil-jassal
sf-sahil-jassal force-pushed the feat/benchmarking-package branch 3 times, most recently from a4cf539 to 3af9248 Compare September 22, 2026 13:35
Comment thread packages/benchmarking/README.md Outdated
@sf-sahil-jassal
sf-sahil-jassal force-pushed the feat/benchmarking-package branch from 3af9248 to 6fafe2b Compare September 24, 2026 01:52
Add a package that lets a team write throughput benchmarks as Mocha
tests, and fail the build when a change makes an operation slower.

The package gives bench.describe() and bench.it(), which wrap tinybench.
Each run keeps its throughput mean in a committed JSON file. The gate
compares the current run against the average of the last ten runs, and
fails the test when the drop is more than the threshold.

Two rules differ from the usual tools. A regressed run is not added to
the history, so a bad merge cannot move the baseline down. And a new
benchmark records samples quietly until it has enough of them, because a
comparison against one prior run is not a signal.

The README gives the full settings list, the rules the gate uses, and
examples of good and bad benchmarks.
@sf-sahil-jassal
sf-sahil-jassal force-pushed the feat/benchmarking-package branch from 6fafe2b to cb05f05 Compare September 24, 2026 01:55
Comment thread packages/benchmarking/src/functions/reporter.function.ts Outdated
Comment thread packages/benchmarking/src/functions/reporter.function.ts Outdated
Comment thread packages/benchmarking/src/functions/bench-it.function.ts
Comment thread packages/benchmarking/package.json Outdated
Comment thread .github/CODEOWNERS
sf-sahil-jassal and others added 2 commits September 29, 2026 14:03
Treat non-object baseline files as corrupt. Drop non-finite history entries.
Report the stored run count. Align engines and @types/node with 22 || 24.
@sonarqubecloud

Copy link
Copy Markdown

@a-ganguly
a-ganguly merged commit 30e1480 into master Oct 1, 2026
8 of 9 checks passed
@a-ganguly
a-ganguly deleted the feat/benchmarking-package branch October 1, 2026 03:00
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.

5 participants