Skip to content

Commit 71e1259

Browse files
committed
Changing task::block_on to park after a single poll
This was previously discussed in #605 and others as a source of high CPU load when sleeping tasks because of the overhead created by retrying a future in short succession.
1 parent 133e30e commit 71e1259

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

Diff for: src/task/block_on.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,14 @@ where
125125
let waker = unsafe { ManuallyDrop::new(Waker::from_raw(RawWaker::new(ptr, &VTABLE))) };
126126
let cx = &mut Context::from_waker(&waker);
127127

128-
let mut step = 0;
129128
loop {
130129
if let Poll::Ready(t) = future.as_mut().poll(cx) {
131130
// Save the parker for the next invocation of `block`.
132131
cache.set(Some(arc_parker));
133132
return t;
134133
}
135134

136-
// Yield a few times or park the current thread.
137-
if step < 3 {
138-
thread::yield_now();
139-
step += 1;
140-
} else {
141-
arc_parker.park();
142-
step = 0;
143-
}
135+
arc_parker.park();
144136
}
145137
})
146138
}

0 commit comments

Comments
 (0)