Skip to content

perf_hooks: add statistical hypothesis testing to histogram - #65416

Open
jasnell wants to merge 2 commits into
nodejs:mainfrom
jasnell:jasnell/more-histogram-fun
Open

perf_hooks: add statistical hypothesis testing to histogram#65416
jasnell wants to merge 2 commits into
nodejs:mainfrom
jasnell:jasnell/more-histogram-fun

Conversation

@jasnell

@jasnell jasnell commented Aug 20, 2026

Copy link
Copy Markdown
Member

Continue expanding the capabilities of the Histogram API... and use it to enable a dependency-free benchmark/compare.js option... i.e. no longer requiring R-script to show benchmark analysis... just run benchmark/compare.js with the --analyze option.

The added algorithms cover analysis calculations that would be fairly common in perf analysis (latency, burn rates, detecting regressions, etc). Prior to this, really the only way to get these were to use aging outside dependencies (5+ years old) or R-script.

Just scratching an old itch I've been wanting since I added Histogram back in v11. I've been doing a bunch of benchmarking lately with the QUIC and DTLS impls and just got tired of having to use outside deps for this stuff.

/cc @mcollina

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance
  • @nodejs/tsc

@jasnell
jasnell requested review from Qard and mcollina August 20, 2026 06:25
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Aug 20, 2026
@jasnell
jasnell force-pushed the jasnell/more-histogram-fun branch from f866877 to bc4d71e Compare August 20, 2026 13:24
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.26230% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.11%. Comparing base (449b950) to head (0793579).
⚠️ Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
src/histogram.cc 92.11% 0 Missing and 29 partials ⚠️
src/histogram-inl.h 86.36% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #65416    +/-   ##
========================================
  Coverage   90.11%   90.11%            
========================================
  Files         752      752            
  Lines      252208   252898   +690     
  Branches    47447    47559   +112     
========================================
+ Hits       227274   227911   +637     
- Misses      16219    16261    +42     
- Partials     8715     8726    +11     
Files with missing lines Coverage Δ
lib/internal/histogram.js 96.09% <100.00%> (+1.32%) ⬆️
src/histogram.h 68.42% <ø> (ø)
src/histogram-inl.h 85.13% <86.36%> (+3.82%) ⬆️
src/histogram.cc 85.41% <92.11%> (+3.74%) ⬆️

... and 56 files with indirect coverage changes

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

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rslgtm

@nodejs-github-bot

This comment was marked as outdated.

@jasnell
jasnell force-pushed the jasnell/more-histogram-fun branch from bc4d71e to 54c4c56 Compare August 20, 2026 19:19
@nodejs-github-bot

This comment was marked as outdated.

@jasnell

jasnell commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

/cc @nodejs/performance

@jasnell jasnell added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Aug 20, 2026
Comment thread lib/internal/histogram.js Outdated
Welch's t-test, Mann-Whitney U test, Cohen's d, and Cliff's delta,
and and handful of others

These methods enable in-process benchmark comparison and regression
detection without external dependencies.

No new dependencies.

Tests and docs created by the AI agent.

Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode/Opus
Add an --analyze flag that performs statistical analysis directly
after benchmarks complete, eliminating the need for R and compare.R.

When --analyze is specified, compare.js collects the rate data during
the run and prints a statistical summary table instead of CSV output.
The table matches the format of compare.R: improvement percentage,
significance stars (* p<0.05, ** p<0.01, *** p<0.001), and confidence
intervals at three risk levels.

Also adds a --max-regression N option that causes the compare.js to
exit with 1 (error) when the `--new` is N% slower. Useful for CI
use to detect regressions.

Uses the histogram API's welchTest() and cohensD() methods introduced
in the previous commit. Benchmark rates are scaled to integers for
HdrHistogram recording; the --scale option (default 1000) controls
the multiplier for precision.

Usage:
  node benchmark/compare.js --old ./node-old --new ./node-new \
    --analyze url

Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode/Opus
@jasnell
jasnell force-pushed the jasnell/more-histogram-fun branch from 54c4c56 to 0793579 Compare August 20, 2026 20:35
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@jasnell jasnell added the commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. label Aug 20, 2026
@jasnell jasnell added the notable-change PRs with changes that should be highlighted in changelogs. label Aug 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The notable-change PRs with changes that should be highlighted in changelogs. label has been added by @jasnell.

Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section.

@jasnell

jasnell commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

Notes for the notable change:

This PR expands the analytical capabilities of Histogram further by adding EWMA, cliffsD, cohensD, SLO burn rate, mannWhitneyTest, and percentile confidence intervals to the API. Notably, this provides the ability to perform performance benchmark analysis directly within Node.js with no dependencies.

@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. needs-ci PRs that need a full CI run. notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants