Conversation
jiengup
marked this pull request as ready for review
September 26, 2026 15:39
This branch has not been deployed
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
Closes #297.
BoundedSender::reserve,try_reserve, and a borrowedmpmc::Permitso callers can wait for capacity before constructing a message, as requested in #297.upstream/main:c42f549(contract tests) and28a0b14(implementation).Design Notes
Queued messages, held permits, and grants to waiting senders share the configured capacity. Sends and reservations receive grants in wait-queue order. Cancelling a granted operation or dropping an unused permit passes its slot to the next waiter. A permit reserves capacity, not message order, and
Permit::sendreturns the value if receivers have disconnected.Benchmarks
Lower is better. Results compare
upstream/main(0f46831) with this branch (28a0b14). Each value is the median of 10 Divan run medians on an Apple M3 Pro with Rust 1.98.0. Microbenchmarks use capacity 1; batch benchmarks use capacity 64 and transfer 16,384 messages per iteration.upstream/maintry_send→try_recvsend→recvsendtry_reserve→Permit::send→try_recvreserve→Permit::send→recvtry_reserve→ drop permitreserve→ drop permittry_reserveon a full queuereserve, then sendExisting single-thread round trips are 5.7%–13.5% slower. Batch results vary by topology and include both improvements and regressions; the largest measured regression is 15.2% for Tokio with 4 workers and 8 producers→1 consumer. Reservation-specific cases were measured in a temporary benchmark copy and are not part of this PR.
Validation
cargo x testpassed, including the bounded MPMC reservation tests and doctests.