You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reduce unbounded MPMC broadcast publish and receive overhead #402
Asyncband's unbounded MPMC broadcast channel retains each value for every eligible receiver. In these comparisons the bounded peers had room for the whole batch and every receiver saw every value. The single-receiver and four-receiver rows measure different costs.
Apple M4 Max, macOS arm64, rustc 1.101.0-nightly. Each cell gives rank, elapsed time relative to Asyncband and the whole-batch median over 10 interleaved runs. Lower is faster. Ecosystem measurements
With usize, allocation counting found one 24-byte allocation per Asyncband publication and zero for Tokio's inline value. In a matched single-receiver run, Asyncband took 292 ms, Tokio with usize took 101 ms, and Tokio publishing a newly allocated Arc<usize> took 245 ms. That control isolates much of the one-receiver gap. The four-reader path also serializes cursor advancement in Backlog::receive under one lock. Its contribution to the larger gap is still unmeasured.
First contribution
Run the command below, then repeat the Tokio comparison with an Arc<usize> payload. Use one and four receiving threads to isolate cursor contention. Keep lossless retention for slow subscribers, delivery to independent subscriptions, and the ability for received values to outlive the backlog or contain a non-Clone payload.
cargo x bench --bench ecosystem -- broadcast/no-backpressure/ --repeat 10 --raw
Could you assign this to me? I'd run broadcast/no-backpressure/ on an Apple M4 (10 cores, macOS 27.0.1), repeat Tokio with Arc<usize>, and use one and four receiving threads to isolate cursor contention.
Since recv returns Arc<T>, the per-message allocation comes with the contract. Your control puts about 144 ms of the 191 ms gap there, so I'd focus on the remaining 47 ms and the four-receiver row. If that's mostly contract too, I'd document it, as #396 allows.
I haven't run these yet. I used Claude to help me read the code.
Reproduced all four rows on Apple M5 (10 cores), macOS 27.0.1, rustc 1.99.1 stable, in a disposable checkout of b1354ae (current main), cargo x bench --bench ecosystem -- broadcast/no-backpressure/ --repeat 10, medians with min..max.
Scenario
Rounds
Asyncband
Tokio
async-broadcast
Publish and try-receive
9,100,000
176 ms (174..200)
95 ms (95..97)
191 ms (190..201)
Publish and await receive
8,000,000
163 ms (162..180)
105 ms (104..111)
182 ms (181..192)
Four publishers, 1 receiver
810
232 ms (226..242)
99 ms (98..100)
222 ms (220..225)
Four receivers drain
500
246 ms (239..254)
80 ms (73..85)
228 ms (224..251)
Against Tokio, the orderings match the issue on every row. The direct-peer picture differs from the issue's host: there async-broadcast led Asyncband on all four rows, while here the two split — async-broadcast ahead on the two multi-party rows, behind on the two single-receiver roundtrips.
I then repeated the comparison with the issue's Arc<usize> control — Tokio publishing a freshly allocated Arc<usize> per message (pointer-sized payload, one allocation per publication) — in the same checkout, interleaved with the other implementations. Adapter registered as a third implementation beside the stock ones; the two-file change is excerpted below.
Control row
Rounds
Asyncband
Tokio (usize)
Tokio (Arc<usize>)
try-receive roundtrip
9,100,000
173 ms (173..216)
95 ms (94..96)
162 ms (161..163)
await-receive roundtrip
8,000,000
162 ms (161..163)
112 ms (111..112)
168 ms (168..169)
Four receivers drain
500
241 ms (239..245)
79 ms (72..93)
91 ms (89..93)
With Tokio allocating once per publish, the try-receive gap shrinks from 1.82x (173/95) to 1.07x (173/162) and the await-receive gap reverses to 0.96x (162/168) — the same direction as the issue's own single-receiver control (292 vs 101 vs 245 ms on M4 Max, where the allocating Tokio run also lands close to Asyncband). The four-receiver drain behaves differently: the control narrows it only from 3.05x (241/79) to 2.65x (241/91). The single-receiver gap shrinks with the allocation control and the drain gap shrinks much less; that difference is consistent with the issue's note that cursor advancement in Backlog::receive serializes under one lock.
Arc control adapter (excerpt; applied to benchmarks/benches/ecosystem/broadcast/mpmc/)
// adapters.rs — a third implementation of the existing BroadcastMpmc trait:// Tokio with T = Arc<usize>, one fresh allocation per send.pubstructTokioArc;implBroadcastMpmcforTokioArc{typeReceiver = tokio::sync::broadcast::Receiver<std::sync::Arc<usize>>;typeSender = tokio::sync::broadcast::Sender<std::sync::Arc<usize>>;fnchannel(capacity:usize,receiver_count:usize) -> (Self::Sender,Vec<Self::Receiver>){let(sender, receiver) = tokio::sync::broadcast::channel(capacity);letmut receivers = Vec::with_capacity(receiver_count);
receivers.push(receiver);for _ in1..receiver_count {
receivers.push(sender.subscribe());}(sender, receivers)}fnsend(sender:&Self::Sender,value:usize){
sender.send(std::sync::Arc::new(value)).unwrap();}fntry_recv(receiver:&mutSelf::Receiver) -> Option<usize>{match receiver.try_recv(){Ok(value) => Some(*value),Err(tokio::sync::broadcast::error::TryRecvError::Empty) => None,Err(error) => panic!("unexpected Tokio receive error: {error}"),}}fnrecv_ready(receiver:&mutSelf::Receiver,context:&mutContext<'_>) -> usize{*poll_ready(receiver.recv(), context).unwrap()}}
// no_backpressure.rs — the control rows reuse the scenario bodies unchanged:
runner.compare("broadcast/no-backpressure/arc-control/try-roundtrip",9_100_000,implementations!([Asyncband,Tokio,TokioArc], |C, b| {
try_send_receive::<C>(b)}),);// likewise arc-control/ready-roundtrip (8_000_000) and arc-control/drain-4r// (500, publish_then_parallel_drain::<C>(b, 4))
Activity
rokadepiyush49-rgb commentedon Nov 6, 2026
Could you assign this to me? I'd run
broadcast/no-backpressure/on an Apple M4 (10 cores, macOS 27.0.1), repeat Tokio withArc<usize>, and use one and four receiving threads to isolate cursor contention.Since
recvreturnsArc<T>, the per-message allocation comes with the contract. Your control puts about 144 ms of the 191 ms gap there, so I'd focus on the remaining 47 ms and the four-receiver row. If that's mostly contract too, I'd document it, as #396 allows.I haven't run these yet. I used Claude to help me read the code.
tisonkun commentedon Nov 6, 2026
Thanks for your interest! We don't assign issues to individual contributors. Anyone is welcome to submit a PR directly for review.
nanami-0713 commentedon Nov 10, 2026
Reproduced all four rows on Apple M5 (10 cores), macOS 27.0.1, rustc 1.99.1 stable, in a disposable checkout of
b1354ae(current main),cargo x bench --bench ecosystem -- broadcast/no-backpressure/ --repeat 10, medians with min..max.Against Tokio, the orderings match the issue on every row. The direct-peer picture differs from the issue's host: there async-broadcast led Asyncband on all four rows, while here the two split — async-broadcast ahead on the two multi-party rows, behind on the two single-receiver roundtrips.
I then repeated the comparison with the issue's
Arc<usize>control — Tokio publishing a freshly allocatedArc<usize>per message (pointer-sized payload, one allocation per publication) — in the same checkout, interleaved with the other implementations. Adapter registered as a third implementation beside the stock ones; the two-file change is excerpted below.Arc<usize>)With Tokio allocating once per publish, the try-receive gap shrinks from 1.82x (173/95) to 1.07x (173/162) and the await-receive gap reverses to 0.96x (162/168) — the same direction as the issue's own single-receiver control (292 vs 101 vs 245 ms on M4 Max, where the allocating Tokio run also lands close to Asyncband). The four-receiver drain behaves differently: the control narrows it only from 3.05x (241/79) to 2.65x (241/91). The single-receiver gap shrinks with the allocation control and the drain gap shrinks much less; that difference is consistent with the issue's note that cursor advancement in
Backlog::receiveserializes under one lock.Arc control adapter (excerpt; applied to
benchmarks/benches/ecosystem/broadcast/mpmc/)Performance tracking issue #396