-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Description
Hi,
nice project!
I just did a small prototype before knowing of this crate, which ended up implementing the same thing as you did.
Although mine is just a prototype, I spotted a simple change you could do to improve your speed a tiny bit:
How
Replace your create function in waker.rs with:
pub fn create() -> impl std::ops::Deref<Target = Waker> {
// Safety: The waker points to a vtable with functions that do nothing. Doing
// nothing is memory-safe.
std::mem::ManuallyDrop::new(unsafe { Waker::from_raw(RAW_WAKER) })
}Nothing else would have to change because you only ever use the waker as reference and ManuallyDrop implements Deref.
Why
Your waker's drop method is a noop because it has no data to clean up.
However the Waker instance doesn't know this and will always call drop resulting in a virtual function call whose body does nothing.
By wrapping the Waker in ManuallyDrop you avoid this single unnecessary function call which is done in each advance call.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels