Implement perf_hooks.createHistogram #8525
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 431 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.363
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #8525"
general
weight: 0.35
littledivy
perf_hooks.createHistogram()threw ERR_METHOD_NOT_IMPLEMENTED. Thehistogramcrate in src/rust/histogram already implements Node.js's nativeHistogramwith the same buckets, rounding and edge cases, but nothing exposed it to JavaScript.In this patch:
node-internal:histogramis a Rust JSG resource overhistogram::Histogram. It is registered with the other Rust Node.js modules. Each histogram reports its counts array to V8 as external memory, about 352 KiB with the default options.src/node/internal/perf_hooks_histogram.tsportsHistogramandRecordableHistogramfrom Node.js 26's lib/internal/histogram.js, with Node.js's argument validation and error codes:- Recording:
record(),recordDelta(),recordCorrected(),add(),subtract()andreset().- Getters:
count,min,max,exceedsand their BigInt variants,mean,stddev,skewness,kurtosis, the EWMA getters andresetCount.- Queries:
percentile(),percentiles,percentilesAt(),cdf(),ccdf(),countAt(),linearBuckets(),logBuckets(),meanCI(),percentileCI()andburnRate().- Comparisons:
ksTest(),welchTest(),mannWhitneyTest(),cohensD()andcliffsD().-
qrde(),snapshot(),diff(),export(),toJSON()andutil.inspect().perf_hooks.importHistogram()reads the data ofexport().structuredClone()of a histogram throws DataCloneError instead of returning an empty object. Node.js clones it, sharing its native handle, which workerd's serializer cannot do yet.node-internal:utilgainsmarkUncloneable(), which sets the serializer's mark as the per-isolate bootstrap'smarkUncloneable()does, so classes in src/node can opt out of being copied as plain objects.recordDelta()usesDate.now(), which in Workers only advances across I/O.qrde()runs on Node.js's thread pool; here it is computed synchronously and returns a resolved promise.The new test runs a set of scenarios over datasets and layouts, covering every method above and its argument errors, and compares the results with what the official x86-64 Node.js 26.12.1 build gives. Everything is compared exactly, including the export bytes and the
inspect()output, except for the results ofmeanCI(),qrde()and the comparisons, which use lgamma, erfc and similar and may differ by a relative 1e-11. The generator is checked in next to the golden file. Node.js's arm64 builds fuse multiplies and adds, and Homebrew's Node.js links a newer HdrHistogram_c, so neither is a reference. The test also ports Node.js's test-perf-hooks-histogram.js, without the parts that needmonitorEventLoopDelay()orMessageChannel.Peak RSS of
workerd test(Linux, opt build) on a Worker that creates histograms:| | before | after |
| --- | --- | --- |
| no histograms | 32 MB | 48 MB |
| 3000x
createHistogram(), not retained | 1092 MB | 123 MB || 3000x
createHistogram(), retained | 1098 MB | 1099 MB || 20x
{ highest: 2n ** 62n, figures: 5 }, retained | 993 MB | 996 MB |Retained histograms keep their memory, but it now counts toward the isolate's limit.
This adds API surface. A call that threw now returns a histogram,
importHistogramis a new export, and nothing else changes, so it is not behind a compatibility flag.monitorEventLoopDelay()still throws. Not included:createSlidingWindowHistogram(), which the crate does not implement, and cloning or transferring a histogram.