feat: add adaptive capacity scaling to ReorderBuffer#3392
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.
f1e29ab to
85b4c27
Compare
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.