Skip to content

Plan: borrowed-view types for zero-allocation percentile queries#16

Merged
thinkingfish merged 4 commits intomainfrom
claude/optimize-percentile-queries-fgONU
Apr 30, 2026
Merged

Plan: borrowed-view types for zero-allocation percentile queries#16
thinkingfish merged 4 commits intomainfrom
claude/optimize-percentile-queries-fgONU

Conversation

@thinkingfish
Copy link
Copy Markdown
Member

Summary

Design notes only — no implementation yet. Captures the plan for adding CumulativeROHistogram*Ref<'a> and SparseHistogram*Ref<'a> borrowed-view types that let columnar consumers (e.g. metriken-query) compute quantiles directly off &[u32] slices without per-snapshot Vec allocation or revalidation.

For a 1k-snapshot × 4-percentile query this drops ~2k transient allocations.

See IMPLEMENTATION_PLAN.md for the full design:

  • Struct layout (Copy, slice-borrowing, lifetime)
  • Constructors: validated from_parts + hot-path from_parts_unchecked
  • Method surface mirroring the read-only API
  • Iterator refactor to slice-holding form (shared between owned and ref)
  • as_ref() / From<&Owned> / IntoIterator / SampleQuantiles impls
  • Macro changes in cumulative.rs and sparse.rs
  • lib.rs re-exports
  • Test matrix
  • CHANGELOG entry + version bump to 1.3.1-alpha.0
  • Out-of-scope notes

Test plan

  • Implementation lands in a follow-up commit on this branch
  • cargo test passes (including new validation/parity/iterator/edge-case tests)
  • cargo clippy --all-targets --all-features -- -D warnings clean
  • cargo doc --no-deps renders new types

https://claude.ai/code/session_01KZce8ZFiJEunLpALcsqxES


Generated by Claude Code

claude and others added 4 commits April 30, 2026 05:39
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>
@thinkingfish thinkingfish marked this pull request as ready for review April 30, 2026 06:33
@thinkingfish thinkingfish merged commit 9fb729c into main Apr 30, 2026
@thinkingfish thinkingfish deleted the claude/optimize-percentile-queries-fgONU branch April 30, 2026 06:40
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.

2 participants