refactor(channels): prototype the 0.7 design - #146
Draft
tisonkun wants to merge 1 commit into
Draft
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.
Status
This is a breaking, correctness-first design draft for the 0.7 channel surface. It is intended to make the complete shape reviewable; it is not proposed as a merge-ready performance replacement.
Summary
mea::channelsync,channel,coordination, andatomic0.7 module groupsatomicboxavailable, while making every new channel implementation independent of bothatomicboxand standard atomicsThe design rationale, ecosystem comparison, invariants, and proposed feature grouping are in
docs/channel-design.md.Public shape
oneshotspsc,mpsc,spmc,mpmcbroadcast::overflowLaggedreportingbroadcast::backpressurebroadcast::unboundedwatchdisruptor::{single_producer,multi_producer}Producer and consumer cardinalities are part of the queue endpoint's nominal type. A single-side endpoint is non-Clone, non-
Sync, and requires mutable access; a multiple-side endpoint is Clone +Syncand uses shared access. Bounded constructors acceptNonZeroUsize, while Disruptor accepts a validated power-of-twoCapacity.Broadcast correctness and policy semantics
The Broadcast log, committed tail, receiver cursors, and waiter metadata are serialized by one state mutex. Publication appends the complete immutable value before advancing the tail, so receivers cannot observe a reservation hole and an older producer cannot overwrite a newer publication after wrap-around. This draft therefore includes the correctness fix explored in #145 while replacing that implementation with the full policy design.
Retention is visible in the endpoint type and API:
sendare synchronous because they never wait for capacitysendis async andtry_sendreportsFullLagged; lossless policies reuse the common receive errorsQueue and waiting model
The queue reference core uses a short mutex-protected
VecDeque, explicit rendezvous handoffs, endpoint counts, and monotonic waiter identities.try_send/try_recvperform the immediate transition; asyncsend/recvregister Wakers and park only the current task. Wakers and replaced or reclaimed user values are released after the internal lock is dropped.Bounded loss is explicit:
force_send(FullBehavior::{DropOldest, DropNewest})returnsSendOutcome::Replaced(value). Ordinarysend().awaitapplies backpressure andtry_sendrejects instead of silently dropping.Disruptor prototype
The multi-producer sequencer separates claim from publication, records per-slot availability generations, and exposes only the highest contiguous published prefix. Subscriber cursors gate wrap-around. The single-producer publisher is statically non-cloneable; the multi-producer publisher is cloneable and concurrent.
This preserves the sequencing contract without copying Java's CAS implementation. It currently parks tasks with Wakers and intentionally omits busy-spin/yield/phased-backoff loops, preallocated mutable event factories, batch translation, and consumer dependency graphs.
0.7 grouping
The draft makes these groups concrete while retaining the non-channel root modules during review:
The document proposes additive umbrella and leaf Cargo features, but does not add conditional compilation in this PR. That migration can follow after the module and endpoint names settle.
Open review questions
sendat the cost of more public types.Stream/Sinkadapters should remain an interoperability layer rather than shape the core state machine.Validation
cargo x lintcargo x test --no-capturecargo +1.85.0 test --workspace --no-default-featurescargo test -p mea channel::tests -- --nocapturecargo x benchThe current benchmark run is only a smoke test. The rewritten oneshot reference measured roughly 60-75 ns locally, slower than the tuned implementation it replaces; topology- and contention-specific benchmarks are required before treating this backend as a performance candidate.