Skip to content

perf: iterate counts[] in value_at_quantile to elide bounds checks#139

Closed
fcostaoliveira wants to merge 1 commit into
HdrHistogram:mainfrom
fcostaoliveira:perf/scan-iter-bce
Closed

perf: iterate counts[] in value_at_quantile to elide bounds checks#139
fcostaoliveira wants to merge 1 commit into
HdrHistogram:mainfrom
fcostaoliveira:perf/scan-iter-bce

Conversation

@fcostaoliveira

Copy link
Copy Markdown

Summary

The value_at_quantile prefix-sum scan iterated with for i in 0..self.counts.len() and indexed
self.counts[i]. Iterating the slice directly with self.counts.iter().enumerate() hands the
element to the loop without a per-element bounds check on the hot path. Results are unchanged.

Benchmark

gnr1 (Intel Granite Rapids), single core, same-session A/B:

before after Δ
value_at_percentile (Mq/s) 0.1742 0.1830 +5.1%

Percentile results byte-identical (the benchmark sink is unchanged). cargo test green;
cargo fmt --check clean.

…ds check

Scan with counts.iter().enumerate() instead of indexing counts[i] in a 0..len loop, so the
element is handed to the loop without a bounds check on the hot prefix-sum path. Results unchanged.
@fcostaoliveira

Copy link
Copy Markdown
Author

Superseded by #140. That PR rewrites the same value_at_quantile scan as a chunked skip-scan (sum a chunk, skip if it can't reach the target, walk only the crossing chunk), which iterates chunks/elements and therefore already elides the per-element bounds check this PR targeted — a strict superset. It measures +63% read (vs the ~+5% here) with a byte-identical parity test across all counter widths. Closing in favor of #140.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant