← Back to Pull requests

Implement perf_hooks.createHistogram #8525

Open
unknown opened this pull request with 431 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 17, 2026 06:18 UTC
Author

perf_hooks.createHistogram() threw ERR_METHOD_NOT_IMPLEMENTED. The histogram crate in src/rust/histogram already implements Node.js's native Histogram with the same buckets, rounding and edge cases, but nothing exposed it to JavaScript.

In this patch:

  • node-internal:histogram is a Rust JSG resource over histogram::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.ts ports Histogram and RecordableHistogram from Node.js 26's lib/internal/histogram.js, with Node.js's argument validation and error codes:

  • - Recording: record(), recordDelta(), recordCorrected(), add(), subtract() and reset().
    - Getters: count, min, max, exceeds and their BigInt variants, mean, stddev, skewness, kurtosis, the EWMA getters and resetCount.
    - Queries: percentile(), percentiles, percentilesAt(), cdf(), ccdf(), countAt(), linearBuckets(), logBuckets(), meanCI(), percentileCI() and burnRate().
    - Comparisons: ksTest(), welchTest(), mannWhitneyTest(), cohensD() and cliffsD().
    - qrde(), snapshot(), diff(), export(), toJSON() and util.inspect().
  • perf_hooks.importHistogram() reads the data of export().

  • 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:util gains markUncloneable(), which sets the serializer's mark as the per-isolate bootstrap's markUncloneable() does, so classes in src/node can opt out of being copied as plain objects.

  • recordDelta() uses Date.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 of meanCI(), 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 need monitorEventLoopDelay() or MessageChannel.

    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, importHistogram is 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.

    Diff: 431 lines (+323 / -108) across 5 files Reviewer: littledivy Review duration: 19720m
    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
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.1% · Safe to merge
    24.1%