ITADN

events_once: sender-dropped-without-set BOUND fast-path via compare_exchange

#201Closedsandersaares 创建于 2026-05-26
S
sandersaarescommented
**Scenario** In `events_once`, the sender-dropped-without-set partial-state benchmark (`sync_sender_dropped_from_bound` / `local_sender_dropped_from_bound` in #197) measures the cost of dropping a Sender that was bound to a Receiver but never called `.set()`. Current measurements: | bench | instructions | | ------------------------------------ | -----------: | | sync_sender_dropped_from_bound | 15 | | local_sender_dropped_from_bound | 14 | **Optimization idea** The current `Event::sender_dropped_without_set` path goes through the general state-transition logic (atomic load + branch on state + atomic store, plus waker handling). For the common case where the state is exactly `BOUND` (no waker registered yet), a single `compare_exchange(BOUND → DISCONNECTED)` could short-circuit the whole thing — fewer atomics, no waker logic. **Expected impact** Modest. The bench measures only 14-15 instructions per call, so absolute savings would be a few instructions per drop. But this is a frequently-traveled path in cancellation-heavy workloads (timeouts, request cancellations, etc.), and even small atomic-elision wins compound. **Tier** This is a "Tier C" candidate — investigate after the Tier A inline work (#TBD - see related inline-investigation issue). **Repro** `just package=events_once bench-cg` and look at the `partial_state_group` scenarios.
关闭于 2026-05-27 1 条评论