sync: use WakeList in Notify and batch_semaphore#4071
Merged
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.
Darksonn
reviewed
Aug 25, 2021
Comment on lines
+6
to
+9
| #[cfg(any(feature = "io-driver", feature = "sync"))] | ||
| mod wake_list; | ||
| #[cfg(any(feature = "io-driver", feature = "sync"))] | ||
| pub(crate) use wake_list::WakeList; |
Member
There was a problem hiding this comment.
Using feature = "io-driver" is incorrect. See the macro definition:
Lines 64 to 80 in 80bda3b
Member
Author
There was a problem hiding this comment.
agh, whoops --- thanks for catching that
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Darksonn
approved these changes
Aug 25, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
PR #4055 added a new
WakeListtype, to manage a potentiallyuninitialized array when waking batches of wakers. This has the
advantage of not initializing a bunch of empty
Options when only asmall number of tasks are being woken, potentially improving performance
in these cases.
Currently,
WakeListis used only in the IO driver. However,tokio::synccontains 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::Notifyandtokio::sync::batch_semaphore::Semaphoreto useWakeListwhen wakingbatches of wakers. This was a pretty straightforward drop-in
replacement.