Skip to content

Commit

Permalink
perf(core): optimize waker capture in AsyncRefCell (denoland#12332)
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Nov 8, 2021
1 parent 80d3a5f commit 4c46862
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/async_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,8 @@ mod internal {
// is updated, it should be impossible to add it to the current borrow.
assert!(id > turn || borrow_count.try_add(M::borrow_mode()).is_none());
// Save or update the waiter's Waker.
// TODO(piscisaureus): Use will_wake() to make this more efficient.
let waiter_mut = waiters[id - turn].as_mut().unwrap();
waiter_mut.set_waker(cx.waker().clone());
waiter_mut.set_waker(cx.waker());
Poll::Pending
}
}
Expand Down Expand Up @@ -593,8 +592,15 @@ mod internal {
self.borrow_mode
}

pub fn set_waker(&mut self, waker: Waker) {
self.waker.replace(waker);
pub fn set_waker(&mut self, new_waker: &Waker) {
if self
.waker
.as_ref()
.filter(|waker| waker.will_wake(new_waker))
.is_none()
{
self.waker.replace(new_waker.clone());
}
}

pub fn take_waker(&mut self) -> Option<Waker> {
Expand Down

0 comments on commit 4c46862

Please sign in to comment.