Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid redundant lookups in the active slab when spawning new tasks #96

Merged
merged 3 commits into from
Feb 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ impl<'a> Executor<'a> {
let mut active = self.state().active.lock().unwrap();

// Remove the task from the set of active tasks when the future finishes.
let index = active.vacant_entry().key();
let entry = active.vacant_entry();
let index = entry.key();
let state = self.state().clone();
let future = async move {
let _guard = CallOnDrop(move || drop(state.active.lock().unwrap().try_remove(index)));
Expand All @@ -164,7 +165,7 @@ impl<'a> Executor<'a> {
.propagate_panic(true)
.spawn_unchecked(|()| future, self.schedule())
};
active.insert(runnable.waker());
entry.insert(runnable.waker());

runnable.schedule();
task
Expand Down Expand Up @@ -398,7 +399,8 @@ impl<'a> LocalExecutor<'a> {
let mut active = self.inner().state().active.lock().unwrap();

// Remove the task from the set of active tasks when the future finishes.
let index = active.vacant_entry().key();
let entry = active.vacant_entry();
let index = entry.key();
let state = self.inner().state().clone();
let future = async move {
let _guard = CallOnDrop(move || drop(state.active.lock().unwrap().try_remove(index)));
Expand All @@ -411,7 +413,7 @@ impl<'a> LocalExecutor<'a> {
.propagate_panic(true)
.spawn_unchecked(|()| future, self.schedule())
};
active.insert(runnable.waker());
entry.insert(runnable.waker());

runnable.schedule();
task
Expand Down
Loading