Plan: borrowed-view types for zero-allocation percentile queries#16
Merged
thinkingfish merged 4 commits intomainfrom Apr 30, 2026
Merged
Plan: borrowed-view types for zero-allocation percentile queries#16thinkingfish merged 4 commits intomainfrom
thinkingfish merged 4 commits intomainfrom
Conversation
Design notes for adding CumulativeROHistogram*Ref and SparseHistogram*Ref view types that let columnar consumers compute quantiles directly off &[u32] slices without per-snapshot allocation or revalidation. https://claude.ai/code/session_01KZce8ZFiJEunLpALcsqxES
Refactor CumulativeIter/QuantileRangeIter/SparseIter structs to hold &[u32] slices directly instead of a reference to the owned histogram, enabling both owned and ref types to return the same iterator type. Add four borrowed-view types generated via the existing macros: - CumulativeROHistogramRef<'a> / CumulativeROHistogram32Ref<'a> - SparseHistogramRef<'a> / SparseHistogram32Ref<'a> Each ref type is Copy and mirrors the read-only API of its owned counterpart (from_parts, from_parts_unchecked, config/index/count accessors, iter, quantiles/quantile, SampleQuantiles trait impl, From<&Owned>, IntoIterator). Cumulative refs additionally expose iter_with_quantiles, bucket_quantile_range, and total_count. Validation logic is DRYed: owned from_parts delegates to the ref type's private validate() fn. Owned quantile methods delegate via as_ref(). New tests cover validation parity, quantile parity, unchecked constructor, From<&Owned>, iterator agreement, bucket_quantile_range, empty/single-sample edge cases, and u32/u64 symmetry (~30 new tests across both files).
Bump version to 1.3.1-alpha.0 (feature PR off main@1.3.0) and add [Unreleased] CHANGELOG entries for the four new ref types, from_parts_unchecked, as_ref(), From<&Owned>, and SampleQuantiles impls. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Design notes only — no implementation yet. Captures the plan for adding
CumulativeROHistogram*Ref<'a>andSparseHistogram*Ref<'a>borrowed-view types that let columnar consumers (e.g. metriken-query) compute quantiles directly off&[u32]slices without per-snapshotVecallocation or revalidation.For a 1k-snapshot × 4-percentile query this drops ~2k transient allocations.
See
IMPLEMENTATION_PLAN.mdfor the full design:Copy, slice-borrowing, lifetime)from_parts+ hot-pathfrom_parts_uncheckedas_ref()/From<&Owned>/IntoIterator/SampleQuantilesimplscumulative.rsandsparse.rslib.rsre-exports1.3.1-alpha.0Test plan
cargo testpasses (including new validation/parity/iterator/edge-case tests)cargo clippy --all-targets --all-features -- -D warningscleancargo doc --no-depsrenders new typeshttps://claude.ai/code/session_01KZce8ZFiJEunLpALcsqxES
Generated by Claude Code