perf_hooks: implement SlidingWindowHistogram - #65825
Draft
jasnell wants to merge 3 commits into
Draft
Conversation
Implements quantile-respectful density estimate calcuation on Histogram. Helps with tail-focused latency analysis without retaining raw samples. Baking this directly into Node.js, based on a 1 million sample, 1k bin workload, this impl is roughly 150-325x faster than performing the equivalent in Rscript. Signed-off-by: James M Snell <[email protected]> Assisted-by: Opencode
The current recordable `Histogram` does not maintain any sense of time. Samples accumulate indefinitely as they are collected. This implements a relatively simple sliding-window mechanism that can be count or time based. The key benefit is that the window remains fixed/bounded while samples are recorded. The sliding window is chunk based. Internally, it maintains a ring buffer of a fixed number of individual histograms. When snapshot() is called, those are materialized into a single combined histogram. As the window slides, older chunks (and all of the samples they hold) are dropped from the window so the window drops however many samples happened to be in that chunk. This does mean that precision of the window is determined by the chunk size. Signed-off-by: James M Snell <[email protected]> Assisted-by: Opencode
Collaborator
|
Review requested:
|
jasnell
marked this pull request as draft
September 5, 2026 16:57
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65825 +/- ##
==========================================
+ Coverage 90.14% 90.18% +0.03%
==========================================
Files 769 770 +1
Lines 262968 265263 +2295
Branches 50052 50407 +355
==========================================
+ Hits 237049 239218 +2169
- Misses 16924 17007 +83
- Partials 8995 9038 +43
🚀 New features to boost your workflow:
|
Signed-off-by: James M Snell <[email protected]> Assisted-by: Opencode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #65806 ... this will remain draft until that lands. The first commit here is from 65806.
Implements
SlidingWindowHistogramAllows for count or time based windows. No timers are used. Validation and allocation are lazy. Uses a ring buffer internally to keep things bounded.
This completes the migration of my typical "performance analysis toolkit" that I've used for some time into built-in primitives.
Example of all this in use: https://github.com/jasnell/fastify-sliding-health