perf: single-pass hdr_value_at_percentiles (flat scan, +599%) - #140
Open
fcostaoliveira wants to merge 1 commit into
Open
perf: single-pass hdr_value_at_percentiles (flat scan, +599%)#140fcostaoliveira wants to merge 1 commit into
fcostaoliveira wants to merge 1 commit into
Conversation
fcostaoliveira
pushed a commit
to redis-performance/hdr-agent-workspace
that referenced
this pull request
Jul 2, 2026
…% (PR #140) hdr_value_at_percentiles: flat counts[] scan (offset==0) replacing the per-bucket iterator; offset-aware iterator fallback kept for decoded histograms. gnr1 same-session A/B: 12,357 -> 86,403 calls/sec (+599%, 7x; 80.9->11.6us). ctest/ASan/nolog green, batch==singular byte-identical, MSVC-safe. Based off official upstream/main (18c7a32), independent of #138/#139. PR HdrHistogram/HdrHistogram_c#140. Logged EXPERIMENTS/SUMMARY/RACE/README/memory.
Contributor
Author
|
|
hdr_value_at_percentiles resolved percentiles via a per-bucket hdr_iter_next walk. When normalizing_index_offset == 0 (the common case), replace it with one tight prefix-sum scan over the flat counts[] array (index->value conversion only at crossings). Decoded/rotated histograms (offset != 0) keep the offset-aware iterator path. Percentiles must be ascending, as before; results are byte-identical. Adds a regression test (test_value_at_percentiles_with_offset) that drives a rotated histogram with normalizing_index_offset != 0 and asserts identical percentiles to the unrotated one, so CI covers the offset-aware fallback.
fcostaoliveira
force-pushed
the
perf/single-pass-value-at-percentiles
branch
from
July 2, 2026 14:40
7c8af3d to
18ab4ee
Compare
Contributor
Author
|
Added a regression test ( |
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.
Summary
hdr_value_at_percentilesresolved the requested percentiles via a per-buckethdr_iter_nextwalk. When
normalizing_index_offset == 0(the common case), replace that with a single tightprefix-sum scan over the flat
counts[]array — the index→value conversion runs only at thecrossings. Decoded/rotated histograms (
normalizing_index_offset != 0) keep the offset-awareiterator path, so behavior is unchanged there.
Percentiles must be ascending (unchanged contract); results are byte-identical.
Benchmark
Getting all 7 of {50,75,90,95,99,99.9,99.99} in one
hdr_value_at_percentilescall, single core(Intel Granite Rapids), same-session A/B on an identical workload (
hdr_init(1, 3.6e9, 3), 1MFibonacci-spread values):
+599% (7×).
hdr_record_valueand singularhdr_value_at_percentileare unchanged (controls flat).Correctness
ctestgreen; ASan + UBSan clean.7 percentiles, unchanged).
normalizing_index_offset == 0case uses the directcounts[]scan; decoded histograms still go through the normalizing iterator.HDR_LOG_REQUIRED=DISABLEDbuilds; no intrinsics (MSVC unaffected).