Optimize TaskPools for use in static variables.#20649
Draft
james7132 wants to merge 85 commits intobevyengine:mainfrom
Draft
Optimize TaskPools for use in static variables.#20649james7132 wants to merge 85 commits intobevyengine:mainfrom
james7132 wants to merge 85 commits intobevyengine:mainfrom
Conversation
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. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Details
#12990 did see some significant improvements to how much overhead was seen in the ECS multi-threaded executor. On
many_foxes: