@@ -2427,6 +2427,82 @@ Returns the values at the specified percentiles, computed in a single
24272427efficient pass over the histogram data. More efficient than calling
24282428` histogram.percentile() ` multiple times.
24292429
2430+ ### ` histogram.qrde([options]) `
2431+
2432+ <!-- YAML
2433+ added: REPLACEME
2434+ -->
2435+
2436+ * ` options ` {Object}
2437+ * ` bins ` {number} The number of equal-probability density bins to return.
2438+ Must be between 1 and 1000. Cannot be used with ` probabilities ` .
2439+ ** Default:** ` 100 ` .
2440+ * ` probabilities ` {number\[ ] } Custom probability boundaries. The array must
2441+ contain between 2 and 1001 strictly increasing values, start with ` 0 ` , and
2442+ end with ` 1 ` . Cannot be used with ` bins ` .
2443+ * ` dequantize ` {string} Controls whether repeated bucket values are spread
2444+ deterministically over their equivalent-value ranges. May be ` 'none' ` ,
2445+ ` 'hdr' ` , or ` 'all' ` . ** Default:** ` 'hdr' ` .
2446+ * ` cache ` {boolean} When ` true ` , retains the expanded histogram snapshot for
2447+ reuse by subsequent calls with ` cache: true ` . The snapshot is invalidated
2448+ when the histogram is modified. ** Default:** ` false ` .
2449+ * Returns: {Promise} Fulfills with an {Object} containing:
2450+ * ` probabilities ` {Float64Array} The probability boundaries used by the
2451+ estimate.
2452+ * ` quantiles ` {Float64Array} The quantiles at the probability boundaries.
2453+ * ` densities ` {Float64Array} The density within each quantile interval.
2454+ * ` count ` {bigint} The number of values in the histogram snapshot.
2455+ * ` bucketCount ` {number} The number of occupied HDR buckets.
2456+ * ` corrections ` {number} The number of non-monotonic floating-point results
2457+ that were clamped to the preceding quantile.
2458+ * ` dequantize ` {string} The selected dequantization mode.
2459+
2460+ Returns a quantile-respectful density estimate based on the Harrell-Davis
2461+ quantile estimator. By default, ` bins ` generates equal probability boundaries.
2462+ The ` probabilities ` option can instead focus the estimate on regions such as
2463+ p90, p99, p99.9, and p99.99. The density for interval ` i ` contains probability
2464+ mass ` probabilities[i + 1] - probabilities[i] ` . The histogram is snapshotted
2465+ when the method is called. Snapshot expansion and the estimate are calculated
2466+ in the libuv thread pool. Highly concentrated beta weights use a second-order
2467+ asymptotic approximation to avoid numerical convergence loss at large sample
2468+ counts.
2469+
2470+ Setting ` cache ` to ` true ` avoids repeating snapshot capture and expansion when
2471+ several estimates are requested from an unchanged histogram. The retained
2472+ snapshot uses memory proportional to the number of occupied HDR buckets and is
2473+ released when the histogram is next modified.
2474+
2475+ QRDE temporarily uses approximately one additional HDR count array plus 32
2476+ bytes per occupied bucket. With ` cache: true ` , the expanded 32-byte-per-bucket
2477+ snapshot remains allocated. The following estimates use ` lowest: 1 ` and
2478+ ` highest: Number.MAX_SAFE_INTEGER ` and exclude allocator and JavaScript object
2479+ overhead:
2480+
2481+ | ` figures ` | Histogram | Maximum expanded snapshot | Peak cache-miss QRDE |
2482+ | --------- | --------: | ------------------------: | -------------------: |
2483+ | 1 | 6.3 KiB | 25 KiB | 31 KiB |
2484+ | 2 | 47 KiB | 188 KiB | 235 KiB |
2485+ | 3 | 352 KiB | 1.4 MiB | 1.7 MiB |
2486+ | 4 | 5.0 MiB | 20 MiB | 25 MiB |
2487+ | 5 | 37 MiB | 148 MiB | 185 MiB |
2488+
2489+ The maximum snapshot column assumes every representable bucket is occupied.
2490+ Lower ` highest ` values reduce histogram and temporary copy sizes. Concurrent
2491+ calls that miss the cache each require their own temporary copy and expanded
2492+ snapshot.
2493+
2494+ HDR histograms aggregate observations into equivalent-value buckets. The
2495+ ` 'hdr' ` dequantization mode models repeated values in buckets wider than one
2496+ unit as a continuous uniform distribution over the bucket resolution. This
2497+ reduces density artifacts introduced by HDR quantization while preserving
2498+ repeated unit-resolution values as point masses. The ` 'all' ` mode also
2499+ dequantizes repeated unit-resolution values. Use ` 'none' ` to calculate the
2500+ grouped Harrell-Davis estimator using bucket midpoints directly.
2501+
2502+ An empty histogram returns the requested ` probabilities ` but produces empty
2503+ ` quantiles ` and ` densities ` arrays. A non-dequantized interval whose quantile
2504+ boundaries are equal has an infinite density.
2505+
24302506### ` histogram.reset() `
24312507
24322508<!-- YAML
0 commit comments