diff --git a/src/runtime.rs b/src/runtime.rs index 5f6cf35..fe57066 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -873,6 +873,15 @@ impl Slot { } fn take_closure(&self) -> Option { + // Fast path: every resume after the first (the overwhelming case) + // finds null. A plain load suffices to prove it — `store_closure` + // runs only before `publish_queued`, whose Release/Acquire pairing + // with the claimer's `try_claim` orders it before this call, so no + // writer can race the load within an occupancy. This keeps the + // locked RMW (full barrier, ~20+ cycles) off the per-resume path. + if self.closure.load(Ordering::Relaxed).is_null() { + return None; + } let raw = self.closure.swap(std::ptr::null_mut(), Ordering::Acquire); if raw.is_null() { None