Index of every page on this site: llms.txt
All skills
jasnell avatar

/node-histogram-stats

@5f83e6c
Run it yourself

Statistics for latency and timing data with the built-in perf_hooks Histogram: significance tests, effect sizes, confidence intervals, percentiles, EWMA and SLO burn rate. Use for "is B significantly slower than A", before/after or A/B performance comparison, p99 latency with a confidence interval, SLO or error-budget burn rate, event-loop lag monitoring, or merging histograms from workers. Use it instead of simple-statistics or hdr-histogram-js. Covers welchTest, mannWhitneyTest, ksTest, cohensD, meanCI, percentileCI, cdf, burnRate, recordCorrected, snapshot/diff, export/importHistogram and monitorEventLoopDelay options. Node.js 24.12+; most need 24.21+ or 26.8+.

Use this Skill: https://skilld.dev/gh/jasnell/node-skills/node-histogram-stats

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

ruleslifecycle.md

≈845 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Lifecycle: snapshot, diff, subtract, export/import, workers

Classes

  • RecordableHistogram comes from createHistogram() or importHistogram(). It has record, recordDelta, recordCorrected, add and subtract.
  • ELDHistogram comes from monitorEventLoopDelay(). It has enable, disable and [Symbol.dispose] (v24.2.0). Over a MessagePort it is cloned as a plain Histogram.
  • Histogram is read-only. snapshot(), diff() and slidingWindow.snapshot() return it.

snapshot() / diff(older) / resetCount (v26.11.0 only)

  • snapshot() is an independent copy that includes the configuration, exceeds and the EWMA state. Later record()/reset() calls do not change it. Its cost scales with lowest/highest/figures, not with the count.
  • newer.diff(older) returns the values recorded in between (count, exceeds and the buckets are differences). It has no EWMA state and its resetCount is 0. Errors (verified):
    • ERR_INVALID_ARG_VALUE: a different lowest/highest/figures, or the wrong order (older.diff(newer)).
    • ERR_INVALID_STATE: the resetCount differs because there was a reset() or subtract() in between.
  • resetCount is incremented by reset() and, on a recordable histogram, by subtract().

Periodic reporting without resetting:

let prev = h.snapshot();
setInterval(() => {
  const cur = h.snapshot();
  const d = cur.resetCount === prev.resetCount ? cur.diff(prev) : cur;
  emit(d.percentile(99));
  prev = cur;
}, 10_000).unref();

add / subtract

  • add(other) (v17.4.0) accepts only a RecordableHistogram. Passing a snapshot throws ERR_INVALID_ARG_TYPE. Observed: a different figures setting is accepted silently, so keep configurations identical yourself.
  • subtract(other) (v26.8.0, v24.21.0) mutates the histogram. Negative bucket counts clamp to 0, and resetCount goes up by one.

export() (v26.9.0; format v2 since v26.11.0) / importHistogram(bytes) (v26.9.0, v24.22.0)

  • export() returns a Uint8Array with a CBOR map of integer keys: 0 version (2), 1 lowest, 2 highest, 3 figures, 4 count, 5 min, 6 max, 7 normalizing offset, 8 conversion ratio, 9 counts length, 10 sparse delta counts, and 11 EWMA state (omitted when disabled). The size scales with the number of distinct values.
  • importHistogram() returns a RecordableHistogram with the buckets, configuration and EWMA restored. It accepts v1 (v26.9.0 output, strict keys) and v2 (unknown keys are ignored). Other versions are rejected.
  • The YAML lists export() only for v26.9.0, while importHistogram also lists v24.22.0. Feature-detect typeof h.export === 'function' on v24.

Merging from workers

Histograms are cloneable over postMessage. Verified: a RecordableHistogram arrives as a RecordableHistogram, so you can post it directly. To send it across processes or store it, post h.export() and call total.add(importHistogram(bytes)) on the receiving side. Use one shared { lowest, highest, figures } configuration on every worker.

bigint variants

countBigInt, minBigInt, maxBigInt, exceedsBigInt, percentileBigInt(p) and percentilesBigInt exist (v17.4.0). record() and recordCorrected() accept bigint. The new statistics methods take and return numbers only. qrde().count is a bigint.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5d3 checks · Risk SAFE
  • Gen Agent Trust Hub5d

    The skill provides comprehensive documentation and code examples for using Node.js built-in performance histogram statistics (available in Node.js 24+). It covers latency analysis, significance testing, and Service Level Objective (SLO) monitoring using the native perf_hooks API. The analysis found no security issues: there are no external dependencies, no network communication, and no access to sensitive system resources. All examples use standard Node.js APIs as intended.

  • Socket5d

    No alerts

  • Snyk5d

    Risk: LOW · No issues

Signed by skilld at 5f83e6c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated last week

README badge

README badge for jasnell/node-skills/node-histogram-stats