Repository navigation
feat: add adaptive capacity scaling to ReorderBuffer - #3392
Merged
Merged
Conversation
This was referenced Apr 26, 2026
Introduce AdaptiveCapacityPolicy as a sibling type composed into ReorderBuffer. The buffer can now grow under sustained pressure (>= 80% utilization with a wide gap window) and shrink back toward the configured minimum once a rolling window of inserts averages below 25% utilization. ReorderStats exposes grow/shrink event counters via a stats() getter. Default fixed-capacity construction is unchanged so existing callers see no behaviour change.
Bind the AdaptiveCapacityPolicy constructor returns to `let _` so the `#[must_use]` attribute is satisfied even though the test bodies are expected to panic before any value is observed.
oferchen
force-pushed
the
feat/reorder-buffer-adaptive-capacity
branch
from
April 26, 2026 09:52
f1e29ab to
85b4c27
Compare
4 tasks
oferchen
added a commit
that referenced
this pull request
Apr 28, 2026
) Task #1853 verification. The concurrent_delta::ReorderBuffer was already converted to a Box<[Option<T>]> ring buffer in #1734 (with adaptive capacity scaling added in #3392), so the BTreeMap-vs-ring decision is already settled in production code. This change adds the scaling benchmark called for in #1853 to confirm O(1) per-item behaviour at the 10M-file scale that motivated the task, and corrects the stale "BTreeMap-backed" doc comment in the concurrent_delta module overview. The benchmark compares the production ring buffer against a self- contained BTreeMap baseline at 10K, 100K, 1M, and 10M items. The 10M case is gated behind BENCH_REORDER_10M=1 so default invocations stay fast; CI can opt in when targeting the scaling regression dataset. No production behaviour changes. Existing reorder_buffer tests already cover gap-larger-than-capacity (force_insert grows the ring) and ring wrap-around.
oferchen
added a commit
that referenced
this pull request
May 1, 2026
* feat: add adaptive capacity scaling to ReorderBuffer Introduce AdaptiveCapacityPolicy as a sibling type composed into ReorderBuffer. The buffer can now grow under sustained pressure (>= 80% utilization with a wide gap window) and shrink back toward the configured minimum once a rolling window of inserts averages below 25% utilization. ReorderStats exposes grow/shrink event counters via a stats() getter. Default fixed-capacity construction is unchanged so existing callers see no behaviour change. * fix: silence unused_must_use clippy in should_panic tests Bind the AdaptiveCapacityPolicy constructor returns to `let _` so the `#[must_use]` attribute is satisfied even though the test bodies are expected to panic before any value is observed.
oferchen
added a commit
that referenced
this pull request
May 1, 2026
) Task #1853 verification. The concurrent_delta::ReorderBuffer was already converted to a Box<[Option<T>]> ring buffer in #1734 (with adaptive capacity scaling added in #3392), so the BTreeMap-vs-ring decision is already settled in production code. This change adds the scaling benchmark called for in #1853 to confirm O(1) per-item behaviour at the 10M-file scale that motivated the task, and corrects the stale "BTreeMap-backed" doc comment in the concurrent_delta module overview. The benchmark compares the production ring buffer against a self- contained BTreeMap baseline at 10K, 100K, 1M, and 10M items. The 10M case is gated behind BENCH_REORDER_10M=1 so default invocations stay fast; CI can opt in when targeting the scaling regression dataset. No production behaviour changes. Existing reorder_buffer tests already cover gap-larger-than-capacity (force_insert grows the ring) and ring wrap-around.
oferchen
added a commit
that referenced
this pull request
May 5, 2026
* feat: add adaptive capacity scaling to ReorderBuffer Introduce AdaptiveCapacityPolicy as a sibling type composed into ReorderBuffer. The buffer can now grow under sustained pressure (>= 80% utilization with a wide gap window) and shrink back toward the configured minimum once a rolling window of inserts averages below 25% utilization. ReorderStats exposes grow/shrink event counters via a stats() getter. Default fixed-capacity construction is unchanged so existing callers see no behaviour change. * fix: silence unused_must_use clippy in should_panic tests Bind the AdaptiveCapacityPolicy constructor returns to `let _` so the `#[must_use]` attribute is satisfied even though the test bodies are expected to panic before any value is observed.
oferchen
added a commit
that referenced
this pull request
May 5, 2026
) Task #1853 verification. The concurrent_delta::ReorderBuffer was already converted to a Box<[Option<T>]> ring buffer in #1734 (with adaptive capacity scaling added in #3392), so the BTreeMap-vs-ring decision is already settled in production code. This change adds the scaling benchmark called for in #1853 to confirm O(1) per-item behaviour at the 10M-file scale that motivated the task, and corrects the stale "BTreeMap-backed" doc comment in the concurrent_delta module overview. The benchmark compares the production ring buffer against a self- contained BTreeMap baseline at 10K, 100K, 1M, and 10M items. The 10M case is gated behind BENCH_REORDER_10M=1 so default invocations stay fast; CI can opt in when targeting the scaling regression dataset. No production behaviour changes. Existing reorder_buffer tests already cover gap-larger-than-capacity (force_insert grows the ring) and ring wrap-around.
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
AdaptiveCapacityPolicy(sibling moduleconcurrent_delta::adaptive) and compose it intoReorderBuffervia a newReorderBuffer::with_adaptive_policyconstructor. DefaultReorderBuffer::new(capacity)behaviour is unchanged.growth_factor(capped atmax) wheninsert()finds utilization >= 80% AND the gap window > current capacity / 2. The grow path also kicks in pre-insert when an incoming sequence would otherwise be rejected, up tomax.minwhen the moving average of the lastsample_windowinsert utilization samples falls below 25%, never evicting buffered items.ReorderStats { grow_events, shrink_events, capacity }is exposed throughReorderBuffer::stats().Test plan
cargo fmt --all(clean against changed files).fmt+clippy,nextest (stable),Windows (stable),macOS (stable),Linux musl (stable).adaptive_tests::fixed_capacity_default_unchanged- default constructor is unaffected.adaptive_tests::adaptive_buffer_starts_at_min_capacityadaptive_tests::grows_under_loadadaptive_tests::never_exceeds_maxadaptive_tests::shrinks_when_idleadaptive_tests::never_drops_below_minadaptive_tests::stats_track_both_eventsadaptive_tests::ordering_preserved_through_resizeadaptive.rscover policy bound validation, grow/shrink predicates, and rolling-window semantics.ReorderBuffertests retained and continue to pass under the unchanged fixed-capacity default path.