-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sync: use WakeList
in Notify
and batch_semaphore
#4071
Conversation
This commit updates `tokio::sync::Notify` to use the `WakeList` type added in PR #4055. This may improve performance somewhat, as it will avoid initializing a bunch of empty `Option`s when waking. I'd like to make similar changes to `BatchSemaphore`, but this is a somewhat larger change, as the wakers stored in the array are not `Waker`s but an internal type, and permit assigning operations are performed prior to waking.
This commit updates the internal semaphore implementation (`batch_semaphore.rs`) to use the new `WakeList` type added in PR #4055.
tokio/src/util/mod.rs
Outdated
#[cfg(any(feature = "io-driver", feature = "sync"))] | ||
mod wake_list; | ||
#[cfg(any(feature = "io-driver", feature = "sync"))] | ||
pub(crate) use wake_list::WakeList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using feature = "io-driver"
is incorrect. See the macro definition:
Lines 64 to 80 in 80bda3b
macro_rules! cfg_io_driver { | |
($($item:item)*) => { | |
$( | |
#[cfg(any( | |
feature = "net", | |
feature = "process", | |
all(unix, feature = "signal"), | |
))] | |
#[cfg_attr(docsrs, doc(cfg(any( | |
feature = "net", | |
feature = "process", | |
all(unix, feature = "signal"), | |
))))] | |
$item | |
)* | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agh, whoops --- thanks for catching that
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Motivation
PR #4055 added a new
WakeList
type, to manage a potentiallyuninitialized array when waking batches of wakers. This has the
advantage of not initializing a bunch of empty
Option
s when only asmall number of tasks are being woken, potentially improving performance
in these cases.
Currently,
WakeList
is used only in the IO driver. However,tokio::sync
contains some code that's almost identical to the code inthe IO driver that was replaced with
WakeList
, so we can apply thesame optimizations there.
Solution
This branch changes
tokio::sync::Notify
andtokio::sync::batch_semaphore::Semaphore
to useWakeList
when wakingbatches of wakers. This was a pretty straightforward drop-in
replacement.