-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Optimize TaskPools for use in static variables. #20649
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
Draft
james7132
wants to merge
85
commits into
bevyengine:main
Choose a base branch
from
james7132:static-executors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This reverts commit 8f1eaa7.
e641bc9 to
a736240
Compare
1 task
Member
Author
|
Ran another set of benchmarks against main, #20331, and this PR. See the PR description for the results. |
NthTensor
approved these changes
Aug 30, 2025
NthTensor
approved these changes
Aug 30, 2025
NthTensor
approved these changes
Aug 30, 2025
Contributor
|
I mixed up which PR I was applying comments to. Disregard this approval for now. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-Tasks
Tools for parallel and async work
C-Performance
A change motivated by improving speed, memory usage or compile times
M-Migration-Guide
A breaking change to Bevy's public API that needs to be noted in a migration guide
S-Blocked
This cannot move forward until something else changes
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
This is a follow-up to #20331 on the path to resolve #1907 sand supersedes #12990. Fixes #11849.
A diff against #20331 can be see here.
Solution
Change all of
Executorto operate on&'static Self. This avoids both the need forArcclones and theactiveSlab for tracking tasks. This removes the need for theMutexlock and twoArccounter increment/decrements when a task is pawned and finishes.TaskPool now wraps a
&'static Executor, either taken from a static variable or via a leaked Box. It's now strongly advised not to use your ownTaskPooland use and configure your the pre-existiing usages (e.g.ComputeTaskPool).NOTE: Right now, the
staticTaskPools are never dropped due to being in static variables. This means that the tasks scheduled onto them are never dropped when the program terminates, meaning that graceful shutdown is harder than it otherwise would be to just drop a TaskPool. This is true without this PR, but this PR bakes that assumption in and will require dedicated graceful shutdown alternatives that require all requisite living tasks be dropped or awaited by the user, then the queues flushed before shutting down the TaskPool threads. This can be quite involved, so an equivalent to#[tokio::main]may be required to fully enforce this, if desired.This PR will remain in draft until #20331 or some equivalent is merged.
Testing
Local testing and benchmarking. Benchmarking results:
#12990 did see some significant improvements to how much overhead was seen in the ECS multi-threaded executor. On
many_foxes: