Skip to content

[Tests] add a benchmark suite - #527

Merged
ljharb merged 1 commit into
ljharb:mainfrom
dvmhmdsd:main
Nov 25, 2026
Merged

ljharb merged 1 commit into
ljharb:mainfrom
dvmhmdsd:main

Conversation

@dvmhmdsd

Copy link
Copy Markdown
Contributor

Motivation

As discussed here #526 for prformance optimiztions, that there should be a benchmarking infrastructure:

  • Run before and after changes to measure impact
    • Execute on every Node.js version in the test matrix
    • Prevent future performance regressions
    • Provide data-driven evidence for performance claims

`npm run benchmark` benchmarks HEAD against every `vX.Y.Z` tag,
several tags in parallel,
and reports each version's parse and stringify speed relative to HEAD at the end.
Each tag runs in its own process alongside HEAD,
alternating case by case,
so the ratios hold up under parallel load.
See `npm run benchmark -- --help` for options.
CI runs it on every push and PR,
not to gate on speed,
but to ensure every version's benchmarks complete.

Benchmarks are from ljharb#527.

Co-authored-by: Mohamed <[email protected]>
Co-authored-by: Jordan Harband <[email protected]>
@socket-security

socket-security Bot commented Jun 20, 2025 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​benchmark@​2.1.41001009875100

View full report

@ljharb ljharb left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

the root package.json's publishConfig.ignore will need "benchmark" added in package.json as well.

Also, can we add a GHA workflow that runs these on every push/PR, and fails if there's a big enough slowdown?

Comment thread benchmark/package.json Resolved
Comment thread benchmark/README.md Resolved
@dvmhmdsd

Copy link
Copy Markdown
Contributor Author

I added most of the comments, will find a way for the GHA @ljharb

@ljharb ljharb left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this seems to be only running benchmarks in node 20.

Comment thread .github/workflows/benchmark.yml Resolved
Comment thread .github/workflows/benchmark.yml Resolved
@dvmhmdsd

Copy link
Copy Markdown
Contributor Author

this seems to be only running benchmarks in node 20.

what versions should it run on ?

@ljharb

ljharb commented Jun 21, 2025

Copy link
Copy Markdown
Owner

Execute on every Node.js version in the test matrix

all of them

@dvmhmdsd

dvmhmdsd commented Jun 22, 2025 •

Copy link
Copy Markdown
Contributor Author

Currently, the benchmarking scripts use some modern features (e.g., Array.from, async/await) and rely on tools that are not compatible with 0.8 like Benchmark.js which I use for benchmarking, which only supports node 0.10. So, is compatibility with Node 0.8 for the benchmarking infrastructure is a hard requirement ? @ljharb

@ljharb

ljharb commented Jun 22, 2025

Copy link
Copy Markdown
Owner

I can definitely live with only going down to 0.10. https://npmjs.com/array.from should cover that one, and async/await can be done with Promises instead, which are polyfillable.

Comment thread .github/workflows/benchmark.yml Resolved
Comment thread benchmark/polyfills.js Resolved
Comment thread benchmark/polyfills.js Resolved
Comment thread benchmark/polyfills.js Resolved
Comment thread benchmark/polyfills.js Resolved
Comment thread benchmark/polyfills.js Resolved
Comment thread benchmark/runner.js Resolved
Comment thread benchmark/runner.js Resolved
Comment thread benchmark/stringify.js Resolved
Comment thread package.json Resolved
Comment thread package.json Resolved
Comment thread package.json Resolved
Comment thread README.md Resolved
@dvmhmdsd

Copy link
Copy Markdown
Contributor Author

Hi @ljharb
Just following up on this PR — I’ve addressed all the comments and happy to make any further changes if needed. Please let me know if there's anything else blocking it from being merged. Thanks.

@ljharb

ljharb commented Apr 27, 2026

Copy link
Copy Markdown
Owner

Sorry for the long delay. If you could rebase this and resolve the conflicts, I can give it a new review.

@ljharb
ljharb marked this pull request as draft April 27, 2026 18:31
@ljharb ljharb mentioned this pull request Oct 28, 2026
@ljharb ljharb changed the title Add comprehensive benchmarking suite [Tests] add a local benchmark suite Nov 25, 2026
@ljharb ljharb changed the title [Tests] add a local benchmark suite [Tests] add a benchmark suite Nov 25, 2026
ljharb pushed a commit to dvmhmdsd/qs that referenced this pull request Nov 25, 2026
`npm run benchmark` benchmarks HEAD against every `vX.Y.Z` tag,
several tags in parallel,
and reports each version's parse and stringify speed relative to HEAD at the end.
Each tag runs in its own process alongside HEAD,
alternating case by case,
so the ratios hold up under parallel load.
Options: `--since <tag>`, `--tags <a,b>`, `--max-time <seconds>` (default 1),
`--concurrency <n>` (default: available parallelism minus 1),
`--cases` for per-case ratios,
and `--parse`, `--stringify`, or `--stress`.

Benchmarks are from ljharb#527.

@ljharb ljharb left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for all the work on this, and sorry again that it sat so long!

I rebased this onto main and reworked it so it can land now. A gate that compares absolute ops/sec against a committed baseline can't work across CI runners and node versions, and the --baseline option never actually reached the runners anyway, so the baseline file, the results/trend reporting, and the CI workflow are gone. The fixtures and the parse/stringify cases are all yours; I just reformatted them for the current lint config and made benchmark a root dev dep.

npm run benchmark now benchmarks HEAD against every tagged version, several at a time, and reports each version's speed relative to HEAD at the end. Each tag runs in its own process alongside HEAD, so the ratios stay meaningful under parallel load.

LGTM, thanks!

@ljharb
ljharb marked this pull request as ready for review November 25, 2026 20:40
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 256 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.07%. Comparing base (7fa2eef) to head (dae810c).

Files with missing lines Patch % Lines
benchmark/index.js 0.00% 111 Missing ⚠️
benchmark/parse.js 0.00% 48 Missing ⚠️
benchmark/run.js 0.00% 39 Missing ⚠️
benchmark/stringify.js 0.00% 38 Missing ⚠️
benchmark/fixtures.js 0.00% 20 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (7fa2eef) and HEAD (dae810c). Click for more details.

HEAD has 39 uploads less than BASE
Flag BASE (7fa2eef) HEAD (dae810c)
78 39
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #527      +/-   ##
===========================================
- Coverage   100.00%   93.07%   -6.93%     
===========================================
  Files            9       14       +5     
  Lines         3443     3699     +256     
  Branches       336      360      +24     
===========================================
  Hits          3443     3443              
- Misses           0      256     +256     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

ljharb added a commit to dvmhmdsd/qs that referenced this pull request Nov 25, 2026
`npm run benchmark` benchmarks HEAD against every `vX.Y.Z` tag,
several tags in parallel,
and reports each version's parse and stringify speed relative to HEAD at the end.
Each tag runs in its own process alongside HEAD,
alternating case by case,
so the ratios hold up under parallel load.
See `npm run benchmark -- --help` for options.
CI runs it on every push and PR,
not to gate on speed,
but to ensure every version's benchmarks complete.

Benchmarks are from ljharb#527.

Co-authored-by: Mohamed <[email protected]>
Co-authored-by: Jordan Harband <[email protected]>
@ljharb
ljharb force-pushed the main branch 2 times, most recently from 317a1ad to 6e4a151 Compare November 25, 2026 21:54
@ljharb
ljharb merged commit 6e4a151 into ljharb:main Nov 25, 2026
442 checks passed
@ljharb ljharb mentioned this pull request Dec 1, 2026
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.

2 participants