Repository navigation
Conversation
Signed-off-by: Zixin Wang <[email protected]>
|
Thanks for benchmarking the shared-read implementation! :3 The mixed read/write result makes a good case for keeping the mutex for small payloads. I’d keep the current bounds for now and record those results in #456. One use case we’d lose is moving a Receiver<Cell> to a worker that only calls changed(). That works in 0.8.1, and #451 explicitly tested that the receiver is Send. We can ask for @tisonkun, with get() and recv() still cloning under the mutex, would you tighten the bounds before 1.0 to keep parallel reads an option for 1.x? |
@QwQBiG Thanks for the review — and good catch on I've recorded the shared-read and bounds-only benchmark results in #456: I'll wait for @tisonkun's call on whether to tighten before 1.0. |
Summary
watch::{Sender, Receiver}are nowSend/Synconly whenT: Send + Sync, matchingtokio::sync::watchand Asyncband's other shared-read primitives. Previously the exclusive value mutex made the endpointsSend + Syncfor anyT: Send, so a cross-threadSender<Cell<_>>could cross threads even though the API never hands out&T.PhantomData<std::sync::RwLock<T>>marker in the private shared state (no unsafe, no runtime cost); the read path is unchanged.# Thread safetysection and twocompile_faildoctests pinningSender<Cell<u8>>: !SendandReceiver<Cell<u8>>: !Sync.CHANGELOG.mdrecords the breaking change with migration guidance.Benchmark
Issue #456 also proposed swapping the exclusive value mutex for a shared read lock so concurrent readers could clone snapshots in parallel. Benchmarks against
mainwith the in-repo suite (Ryzen 5 5600H,--repeat 10, alternating runs) showed that variant regressingwatch/getby 9% andwatch/concurrent-read-writeby 61%, caused by stdRwLockreader-count contention and writers waiting on readers; the other three watch scenarios were unchanged. The shared-read path was dropped, and this PR ships the bounds tightening only. All five scenarios are at parity withmain(for examplewatch/get348-350 ms vs 349 ms), so concurrent-read optimization is left for a future design that avoids the lock.Verification
cargo x build,cargo x testcargo +nightly x check(feature matrix with-Dwarnings)cargo +nightly x lintcargo +nightly x miriwith the CIMIRIFLAGS(72 suites)Fixes #456