Repository navigation
Conversation
tisonkun
reviewed
Nov 25, 2026
Member
There was a problem hiding this comment.
Looks like a random internal utility. Why do we need to generalize it?
Contributor
Author
There was a problem hiding this comment.
I tried to dedup the local target_has_atomic = "64" wrappers (watch, mpsc, broadcast), but you're right — mixing broadcast's claim_next with the rest isn't worth generalizing. I'll drop it, keep them local, and move broadcast_wake back under broadcast/mpmc/unbounded.
Contributor
Author
Benchmark Results (
|
| Benchmark | origin/main |
PR #473 | Delta | Tokio | AsyncBroadcast |
|---|---|---|---|---|---|
broadcast/no-backpressure/try-roundtrip |
152 ms | 153 ms | +0.7% | 106 ms | 234 ms |
broadcast/no-backpressure/try-roundtrip-shared |
151 ms | 153 ms | +1.3% | 200 ms | 362 ms |
broadcast/no-backpressure/ready-roundtrip |
138 ms | 139 ms | +0.7% | 129 ms | 224 ms |
broadcast/no-backpressure/publish-4p-drain-1r |
343 ms | 329 ms | -4.1% | 157 ms | 406 ms |
broadcast/no-backpressure/sequential-drain-4r |
296 ms | 288 ms | -2.7% | 238 ms | 444 ms |
broadcast/no-backpressure/drain-4r |
279 ms | 301 ms | +7.9% | 242 ms | 1,127 ms |
broadcast/no-backpressure/drain-4r-shared |
280 ms | 283 ms | +1.1% | 363 ms | 1,522 ms |
broadcast::mpmc::unbounded (Primitives)
| Benchmark | origin/main |
PR #473 | Delta |
|---|---|---|---|
send_and_try_recv_shared |
101 ms | 101 ms | 0.0% |
send_and_try_recv_string_shared |
140 ms | 140 ms | 0.0% |
send_and_try_recv_string_cloned_sole |
143 ms | 146 ms | +2.1% |
send_and_try_recv_string_cloned_fanout |
192 ms | 195 ms | +1.6% |
deliver_to_waiting_receiver |
187 ms | 180 ms | -3.7% |
register_and_deliver_fanout/1 |
578 ms | 616 ms | +6.6% |
register_and_deliver_fanout/4 |
258 ms | 261 ms | +1.2% |
register_and_deliver_fanout/16 |
193 ms | 181 ms | -6.2% |
send_without_receivers |
43 ms | 45 ms | +4.7% |
try_recv_empty |
63 ms | 63 ms | 0.0% |
drain_with_receivers/peak 1 live 1 |
160 ms | 161 ms | +0.6% |
drain_with_receivers/peak 8 live 8 |
36 ms | 34 ms | -5.6% |
drain_with_receivers/peak 8 live 1 |
162 ms | 160 ms | -1.2% |
drain_with_receivers/peak 32 live 32 |
36 ms | 34 ms | -5.6% |
drain_with_receivers/peak 32 live 4 |
63 ms | 49 ms | -22.2% |
drain_with_receivers/peak 32 live 1 |
162 ms | 160 ms | -1.2% |
drain_with_receivers/peak 256 live 32 |
35 ms | 34 ms | -2.9% |
drain_with_receivers/peak 256 live 1 |
161 ms | 160 ms | -0.6% |
cancel_pending |
263 ms | 252 ms | -4.2% |
mpsc::bounded & mpsc::reservation (Ecosystem, --baseline-only)
| Benchmark | origin/main |
PR #473 | Delta |
|---|---|---|---|
mpsc/bounded/try-roundtrip |
148 ms | 148 ms | 0.0% |
mpsc/bounded/ready-roundtrip |
142 ms | 146 ms | +2.8% |
mpsc/bounded/ready-roundtrip-inline1k |
125 ms | 124 ms | -0.8% |
mpsc/bounded/ready-roundtrip-boxed1k |
45 ms | 45 ms | 0.0% |
mpsc/bounded/threads-4p1c-cap64 |
200 ms | 227 ms | +13.5% |
mpsc/bounded/tasks-1p1c-cap64-4w |
211 ms | 217 ms | +2.8% |
mpsc/bounded/tasks-4p1c-cap64-4w |
262 ms | 203 ms | -22.5% |
mpsc/bounded/tasks-1p1c-cap1024-4w |
138 ms | 61 ms | -55.8% |
mpsc/bounded/tasks-4p1c-cap1024-4w |
302 ms | 409 ms | +35.4% |
mpsc/bounded/tasks-1p1c-cap64-current |
184 ms | 188 ms | +2.2% |
mpsc/bounded/tasks-1p1c-cap1024-current |
165 ms | 166 ms | +0.6% |
mpsc/bounded/tasks-4p1c-cap64-current |
189 ms | 189 ms | 0.0% |
mpsc/bounded/tasks-4p1c-cap64-4w-inline1k |
83 ms | 91 ms | +9.6% |
mpsc/bounded/tasks-4p1c-cap64-4w-boxed1k |
57 ms | 70 ms | +22.8% |
mpsc/bounded/tasks-4p1c-cap1-4w |
288 ms | 292 ms | +1.4% |
mpsc/bounded/external-receiver-1p1c-cap64-4w |
237 ms | 240 ms | +1.3% |
mpsc/reservation/reserve-publish-receive |
104 ms | 104 ms | 0.0% |
mpsc/reservation/tasks-4p1c-cap1-4w |
298 ms | 327 ms | +9.7% |
Notes:
mpsc/bounded/tasks-1p1c-cap1024-4wdrops from 138 ms to 61 ms (-55.8%) andtasks-4p1c-cap64-4wdrops from 262 ms to 203 ms (-22.5%) because non-ZST receivers armSLOT_RX_WAITINGon the head slot rather than stealing the producer-hottailcache line viaRX_WAITING_BIT.mpsc/bounded/tasks-4p1c-cap1024-4wshows a bistable 5-task-on-4-worker scheduling regime (minobserved at ~291 ms vsorigin/main~268 ms, while median shifts from 302 ms to 409 ms as the 4 producers synchronize onacquiredCAS retries; still well ahead of Tokio ~620 ms).broadcast::mpmc::unboundedremains at parity or slightly faster across steady-state, fan-out, and cancellation benchmarks (publish-4p-drain-1r-4.1%,deliver_to_waiting_receiver-3.7%,cancel_pending-4.2%,register_and_deliver_fanout/16-6.2%) while eliminating 58 -> 18unsafeblocks (unsafe fn11 -> 1) and all epoch/pool raw-pointer management.
biaoma-ty
force-pushed
the
refactor/deep-channel-primitives
branch
4 times, most recently
from
November 28, 2026 10:23
9bc0da1 to
7b0f5bb
Compare
Unify non-ZST receiver slot waiting on the head slot state, co-locate hot producer counters onto one cache line, relax proven orderings, and extract the shared GrantWaiter helper used across mpsc and mpmc. Part of apache#396 Signed-off-by: Biao Ma <[email protected]>
…nd sharded rwlock Replace manual raw-pointer segment allocation, reference counting, spare pooling, and 3-epoch garbage collection in broadcast::mpmc::unbounded with uniform Arc-owned segments (plus 8 inline genesis slots), an epoch-free 4-shard reader-writer lock, and a single-lock BroadcastWake coordinator. Part of apache#396 Signed-off-by: Biao Ma <[email protected]>
biaoma-ty
force-pushed
the
refactor/deep-channel-primitives
branch
from
November 28, 2026 10:28
7b0f5bb to
5ec7b5a
Compare
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
broadcast::mpmc::unboundedontoArc-owned segments and an epoch-free sharded rwlock (broadcast::mpmc::unbounded): Removesegment.rsalong with manualalloc_zeroed/deallocheap segments, custom segment refcounting, spare pooling,prevback-pointers,unlinked_nextsentinels,OnceLock<Box<ExtraShards>>, and 3-epoch garbage collection. Replace them with uniformArc<Segment<T>>blocks (with iterativeDropand 8 inline genesis slots inShared<T>), a 4-shardShardedRwLock<State<T>>that immediately releases retired tail segments on write-guard handoff, and a single-mutexBroadcastWakecoordinator inbroadcast::mpmc::unbounded::waitersthat preserves the sync-before-async wakeup order from fix(broadcast): notify sync in-flight slot waiters before async wakers #470.mpsc::boundedreceiver waits and shareGrantWaiter(mpsc::bounded,mpmc,internal::grant_waiter): Unify non-ZST receiver empty and in-flight waiting ontoslot[head].state = SLOT_RX_WAITING, co-locate hot producer counters onto one cache line, relax proven orderings onacquiredandslot_state, unifytry_acquire_slow<const SEQCST>andrelease_locked/release_slow, and extract the sharedGrantWaiterwait-list helper acrossmpscandmpmc.Overall diff removes 766 net lines against
main(+1,482 / -2,248), cutsbroadcast::mpmc::unboundedunsafeblocks from 58 to 18 (unsafe fnfrom 11 to 1), and improves multi-taskmpsc::bounded(tasks-1p1c-cap1024-4wandtasks-4p1c-cap64-4w) and concurrentbroadcast::mpmc::unbounded(publish-4p-drain-1randdrain-4r) throughput.Follows up on #465, #469, and #470. Part of #396.
Design Notes
ShardedRwLock<State<T>>without epochs: Publishers take a per-sender shard read guard (&State<T>) with zero reader cache-line contention across 4 producers and zeroAtomicPtr/ epoch retirement machinery. Subscription changes and tail segment advances take exclusive write access so supersededArc<Segment<T>>handles drop immediately outside the lock;advance_receiver_seg(reachable fromFuture::poll) only uses non-blockingtry_write()sopoll_recvnever spins or yields.mpsc::bounded: Non-ZST receivers armSLOT_RX_WAITINGdirectly onslot[head]instead of setting and clearingRX_WAITING_BITon the producer-hottailatomic, avoiding receiver-inducedtailcache-line bounces while keepingRX_WAITING_BITsolely for zero-sized channels without slot storage.Validation
cargo x check(across--no-default-features, every feature individually, and--all-features)cargo x test(full workspace)cargo x lint(nightly clippy, rustfmt, taplo, typos, hawkeye, docsrs rustdoc-D warnings)cargo +1.86.0 check --package asyncband --all-features --testsMIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-many-seeds=0..4" cargo +nightly miri test --package asyncband --lib --features broadcast,mpsc,mpmc(broadcast::mpmc::unboundedandmpsc::bounded)MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check" cargo +nightly miri test --package tests-integration --test broadcast_test --test mpsc_test --test mpmc_test --test traits_test