feat: bounded-memory spill-to-tempfile for ReorderBuffer#3982
Merged
Conversation
When the in-memory reorder buffer exceeds a configurable threshold (default 64 MB), excess items are serialized to a temporary file and reloaded transparently on delivery. This bounds memory for 100K+ file transfers where head-of-line stalls cause successor accumulation. Key components: - SpillCodec trait for item serialization (length-prefixed binary) - SpillableReorderBuffer<T> wrapper with same API as ReorderBuffer - SpillCodec implementation for DeltaResult - ReorderBuffer::take() for non-advancing slot extraction - SpooledTempFile (in-memory up to 1 MB, then disk) via tempfile crate - Hot-zone protection keeps items near next_expected in memory - RAII cleanup: temp files removed automatically on drop
oferchen
added a commit
that referenced
this pull request
May 18, 2026
…3982) When the in-memory reorder buffer exceeds a configurable threshold (default 64 MB), excess items are serialized to a temporary file and reloaded transparently on delivery. This bounds memory for 100K+ file transfers where head-of-line stalls cause successor accumulation. Key components: - SpillCodec trait for item serialization (length-prefixed binary) - SpillableReorderBuffer<T> wrapper with same API as ReorderBuffer - SpillCodec implementation for DeltaResult - ReorderBuffer::take() for non-advancing slot extraction - SpooledTempFile (in-memory up to 1 MB, then disk) via tempfile crate - Hot-zone protection keeps items near next_expected in memory - RAII cleanup: temp files removed automatically on drop
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
SpillableReorderBuffer<T>that wrapsReorderBuffer<T>with transparent disk-backed overflow when in-memory footprint exceeds a configurable threshold (default 64 MB)SpillCodectrait for item serialization using a simple length-prefixed binary format, with implementation forDeltaResultReorderBuffer::take()for non-advancing slot extraction, enabling the spill layer to extract items without disturbing delivery orderDesign
When successor items accumulate in the reorder buffer due to head-of-line stalls (e.g., a slow delta computation blocks delivery of 100K+ subsequent items), memory grows unboundedly. This PR bounds memory by spilling the highest-sequence items (furthest from delivery) to a
SpooledTempFile(in-memory up to 1 MB, then rolls to disk). A hot zone aroundnext_expectedis preserved in memory to avoid thrashing. Items are reloaded transparently when their sequence reaches the delivery cursor.The spill format is a simple
[u32 len][payload]record per item, indexed byBTreeMap<sequence, file_offset>for O(log S) reload. Temp files are cleaned up automatically via RAII (Drop).Test plan
Closes #1884