-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
io: speed-up waking by using uninitialized array (#4055)
- Loading branch information
Gleb Pomykalov
authored
Aug 25, 2021
1 parent
897fed1
commit 51f4f05
Showing
3 changed files
with
58 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use core::mem::MaybeUninit; | ||
use core::ptr; | ||
use std::task::Waker; | ||
|
||
const NUM_WAKERS: usize = 32; | ||
|
||
pub(crate) struct WakeList { | ||
inner: [MaybeUninit<Waker>; NUM_WAKERS], | ||
curr: usize, | ||
} | ||
|
||
impl WakeList { | ||
pub(crate) fn new() -> Self { | ||
Self { | ||
inner: unsafe { MaybeUninit::uninit().assume_init() }, | ||
curr: 0, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn can_push(&self) -> bool { | ||
self.curr < NUM_WAKERS | ||
} | ||
|
||
pub(crate) fn push(&mut self, val: Waker) { | ||
debug_assert!(self.can_push()); | ||
|
||
self.inner[self.curr] = MaybeUninit::new(val); | ||
self.curr += 1; | ||
} | ||
|
||
pub(crate) fn wake_all(&mut self) { | ||
assert!(self.curr <= NUM_WAKERS); | ||
while self.curr > 0 { | ||
self.curr -= 1; | ||
let waker = unsafe { ptr::read(self.inner[self.curr].as_mut_ptr()) }; | ||
waker.wake(); | ||
} | ||
} | ||
} | ||
|
||
impl Drop for WakeList { | ||
fn drop(&mut self) { | ||
let slice = ptr::slice_from_raw_parts_mut(self.inner.as_mut_ptr() as *mut Waker, self.curr); | ||
unsafe { ptr::drop_in_place(slice) }; | ||
} | ||
} |
51f4f05
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.
Possible performance regression was detected for benchmark 'sync_mpsc'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.send_large
62527
ns/iter (± 28976
)26175
ns/iter (± 5653
)2.39
This comment was automatically generated by workflow using github-action-benchmark.
CC: @tokio-rs/maintainers
51f4f05
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.
Possible performance regression was detected for benchmark 'sync_mpsc'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.send_large
58252
ns/iter (± 9867
)26175
ns/iter (± 5653
)2.23
This comment was automatically generated by workflow using github-action-benchmark.
CC: @tokio-rs/maintainers
51f4f05
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.
Possible performance regression was detected for benchmark 'sync_mpsc'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.send_large
58576
ns/iter (± 4887
)26175
ns/iter (± 5653
)2.24
This comment was automatically generated by workflow using github-action-benchmark.
CC: @tokio-rs/maintainers