Skip to content

feat: add adaptive capacity scaling to ReorderBuffer#3392

Merged
oferchen merged 2 commits intomasterfrom
feat/reorder-buffer-adaptive-capacity
Apr 26, 2026
Merged

feat: add adaptive capacity scaling to ReorderBuffer#3392
oferchen merged 2 commits intomasterfrom
feat/reorder-buffer-adaptive-capacity

Conversation

@oferchen
Copy link
Copy Markdown
Owner

Summary

  • Introduce AdaptiveCapacityPolicy (sibling module concurrent_delta::adaptive) and compose it into ReorderBuffer via a new ReorderBuffer::with_adaptive_policy constructor. Default ReorderBuffer::new(capacity) behaviour is unchanged.
  • Buffer grows by growth_factor (capped at max) when insert() 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 to max.
  • Buffer shrinks back toward min when the moving average of the last sample_window insert utilization samples falls below 25%, never evicting buffered items.
  • ReorderStats { grow_events, shrink_events, capacity } is exposed through ReorderBuffer::stats().

Test plan

  • cargo fmt --all (clean against changed files).
  • CI: fmt+clippy, nextest (stable), Windows (stable), macOS (stable), Linux musl (stable).
  • New unit tests:
    • adaptive_tests::fixed_capacity_default_unchanged - default constructor is unaffected.
    • adaptive_tests::adaptive_buffer_starts_at_min_capacity
    • adaptive_tests::grows_under_load
    • adaptive_tests::never_exceeds_max
    • adaptive_tests::shrinks_when_idle
    • adaptive_tests::never_drops_below_min
    • adaptive_tests::stats_track_both_events
    • adaptive_tests::ordering_preserved_through_resize
  • Module-level tests in adaptive.rs cover policy bound validation, grow/shrink predicates, and rolling-window semantics.
  • All pre-existing ReorderBuffer tests retained and continue to pass under the unchanged fixed-capacity default path.

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 oferchen force-pushed the feat/reorder-buffer-adaptive-capacity branch from f1e29ab to 85b4c27 Compare April 26, 2026 09:52
@oferchen oferchen merged commit 5f06641 into master Apr 26, 2026
40 of 41 checks passed
@oferchen oferchen deleted the feat/reorder-buffer-adaptive-capacity branch April 26, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant