perf(mpsc): streamline unbounded buffer reclamation - #295
Merged
Conversation
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
Unbounded receiver refills currently release retired batch allocations and oversized empty segment directories while holding the shared state mutex. Receiving also checks the last message and allocation capacity even for payload types whose segments cannot exceed the byte budget. Release retired storage after unlocking, and select oversized-payload reclamation at compile time so ordinary messages use the normal local pop path.
Make segment capacity and the retained directory's slot limit associated constants, with a named directory byte budget. Power-of-two growth keeps ordinary segments within 32 KiB; oversized payloads use one slot and release their backing allocation when consumed. A focused boundary test checks that growth, sealing, and buffer reuse preserve the capacity invariant around payload-size thresholds.
Validated with
cargo x teston the default nightly and Rust 1.86.0,cargo x lint --fix,cargo x check,cargo x bench --no-run, and the fullcargo x miriworkflow. Benchmark adapters, extra measurement cases, and raw results are outside the repository.Benchmarks compare main
7ad6d68d45a3b74506d9a605e594c417e80d506bwith the final implementation in the same executable on an Apple M4 Max, macOS 26.6.2, rustc 1.99.0-nightly (3d6c19bb9). Values are medians of ten round medians, with randomized implementation order, 100 samples per case, 1,000 iterations per microbenchmark sample, and one batch per throughput sample. Coverage includes all 21 existing unbounded workloads, two 4,096-message inline bursts, and a 32-message burst of 64 KiB payloads. Async workloads transfer 16,384 messages per sample; inline async bursts use four runtime workers.The sequential inline/boxed payload improvements occur in all ten paired rounds. Most usize throughput workloads remain close to main; the largest measured increase versus main is 0.5% in the 1,024-message retained-backlog case. These are workload-specific measurements on this machine, not a claim of uniform improvement across platforms.