From 81aa6d152a6be24f1ba19e63ad78318315a67c07 Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Mon, 20 Jan 2020 20:40:01 +0100 Subject: [PATCH] Changing task::block_on to park after a single poll (#684) 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. --- src/task/block_on.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/task/block_on.rs b/src/task/block_on.rs index 80259c57..a994ee7d 100644 --- a/src/task/block_on.rs +++ b/src/task/block_on.rs @@ -3,7 +3,6 @@ use std::future::Future; use std::mem::{self, ManuallyDrop}; use std::sync::Arc; use std::task::{RawWaker, RawWakerVTable}; -use std::thread; use crossbeam_utils::sync::Parker; use kv_log_macro::trace; @@ -125,7 +124,6 @@ where let waker = unsafe { ManuallyDrop::new(Waker::from_raw(RawWaker::new(ptr, &VTABLE))) }; let cx = &mut Context::from_waker(&waker); - let mut step = 0; loop { if let Poll::Ready(t) = future.as_mut().poll(cx) { // Save the parker for the next invocation of `block`. @@ -133,14 +131,7 @@ where return t; } - // Yield a few times or park the current thread. - if step < 3 { - thread::yield_now(); - step += 1; - } else { - arc_parker.park(); - step = 0; - } + arc_parker.park(); } }) }