Repository navigation
Futex: skip timer path and redundant bucket-lock for untimed waits - #536
Conversation
timedWaitClock unconditionally ran removeFromBucket after every wake to determine the timeout-vs-wake winner. For an untimed (.none) wait there is no timer, so that check can never observe a timeout — it is a pure-waste second bucket-mutex acquisition on the hottest blocking path. Short-circuit .none to the untimed wait(), which parks without a timer and relies on wake() to dequeue the waiter (one bucket-mutex acquisition instead of two). This speeds up every std.Io futex waiter on zio (Mutex, Condition, Queue, Semaphore), since they all issue untimed io.futexWait calls: ~8% on a two-task queue ping-pong for both std.Io.Queue and a hand-rolled channel.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesFutex Timed Wait Short-Circuit
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
Futex.timedWaitClockalways ranremoveFromBucketafter a wake to decide the timeout-vs-wake winner (a second bucket-mutex acquisition), and drove the timed waiter path — even when the caller passed no deadline (.none).For an untimed wait there is no timer, so that post-wake
removeFromBucketcan never observe a timeout. It's pure waste on the hottest blocking path: every untimed wait took the bucket mutex twice (push + removeFromBucket) instead of once.This short-circuits
.noneto the existing untimedwait(), which parks without a timer and letswake()dequeue the waiter — one bucket-mutex acquisition instead of two.Why it matters broadly
Every
std.Iosynchronization primitive on zio issues untimedio.futexWaitcalls (Mutex.lockunder contention,Condition.wait,Queue,Semaphore), and they all flow throughFutex.timedWaitClockvia the io vtable. So this one line benefits the wholestd.Iosync layer, not just directFutexusers.Measurement
A two-task 100k-message queue ping-pong, normalized against a native-
Channelrun as an ambient-load control (native parks viaWaiterdirectly and does not hitFutex.timedWaitClock):std.Io.Queue(relative to control)Testing
./check.sh— 507/507 unit tests pass. No behavioral change for timed waits;.nonewaits keep identical semantics (cancelable, spurious-wake-safe), just without the timer setup and the extra bucket-mutex round-trip.