-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Optimize TaskPools for use in static variables. #12990
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
base: main
Are you sure you want to change the base?
Conversation
10dfdd6
to
c8dd6a5
Compare
Co-authored-by: Afonso Lage <[email protected]>
Do you see much change in the actual frame time? The duplication of all the unsafety of |
With this PR, we could probably just remove and/or replace |
Objective
Fixes #11849. async_executor internally locks a
Mutex
each time it spawns and finishes a task. This adds a significant amount of overhead for any operation interacting with the task pools, even in single-threaded cases. For more information, see smol-rs/async-executor#112.Solution
Create a const-constructible version of
TaskPool
that usesStaticExecutor
instead ofExecutor
. Use it to back the static TaskPools instead. This also eliminates theOnceLock
on trying to fetch the task pool as the a raw'static
borrow on the static variable can be returned without issue. This solution is loosely based on the work in #4740 to specialize a fork of async_executor for Bevy.This is blocked on
async_executor
andconcurrent_queue
pushing new releases with the necessary changes.TODO: This PR duplicates a huge amount of code currently due to the change in the lifetime requirements on
self
needed to useStaticExecutor
's API.TODO: The docs are still copied over from TaskPool and needs to be rewritten.
Performance
See the benchmarks in smol-rs/async-executor#112. For both single threaded and multithreaded use cases, the overhead of launching, ticking, and finishing tasks is lower, potentially upwards of 9x lower in multithreaded cases under contention.
Future Work
To lower the overhead other use cases like
scope
s, the LocalExecutors and ThreadExecutors may also benefit from being replaced in this fashion too.Changelog
TODO
Migration Guide
TODO