You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
pubfncreate() -> 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.
The text was updated successfully, but these errors were encountered:
peterhj
pushed a commit
to peterhj/genawaiter
that referenced
this issue
Aug 31, 2023
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 inwaker.rs
with:Nothing else would have to change because you only ever use the waker as reference and
ManuallyDrop
implementsDeref
.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 calldrop
resulting in a virtual function call whose body does nothing.By wrapping the
Waker
inManuallyDrop
you avoid this single unnecessary function call which is done in eachadvance
call.The text was updated successfully, but these errors were encountered: