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

Immediately poll the executor once before spawning it as a task #11801

Merged
merged 2 commits into from
Feb 12, 2024

Conversation

james7132
Copy link
Member

@james7132 james7132 commented Feb 9, 2024

Objective

At the start of every schedule run, there's currently a guaranteed piece of overhead as the async executor spawns the MultithreadeExecutor task onto one of the ComputeTaskPool threads.

Solution

Poll the executor once to immediately schedule systems without waiting for the async executor, then spawn the task if and only if the executor does not immediately terminate.

On a similar note, having the executor task immediately start executing a system in the same async task might yield similar results over a broader set of cases. However, this might be more involved, and may need a solution like #8304.

@james7132 james7132 added A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times labels Feb 9, 2024
@JMS55 JMS55 added this to the 0.13 milestone Feb 10, 2024
@hymm hymm self-requested a review February 10, 2024 02:11
@hymm
Copy link
Contributor

hymm commented Feb 11, 2024

Seeing decent gains on AssetEvents, UpdateAssets, and PreUpdate. All the other schedules were pretty neutral. I'm guessing this helps the most when there are a bunch of systems that are ready to run right away and hurts a little because the main thread is more likely to go to sleep, since the systems are more likely to get stolen and run on other threads.

AssetEvents
image

UpdateAssets
image

PreUpdate
image

@james7132
Copy link
Member Author

Yep, this has the strongest impact on schedules with a large number of unblocked systems that have very little to do, which is surprisingly common. These little bits tend to add up, so it ends up being a death by a thousand cuts.

I think this is good proof that there's a lot we're leaving on the table when it comes to scheduling overhead, and an eventual solution like #8304 may be able to help.

@mockersf mockersf added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 11, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 12, 2024
Merged via the queue into bevyengine:main with commit 87add56 Feb 12, 2024
24 checks passed
@inodentry
Copy link
Contributor

I'd like to take this moment to ask:

Why are AssetEvents and UpdateAssets separate from PreUpdate anyway? Wouldn't it be better if they were part of PreUpdate and use system sets / ordering inside of PreUpdate?

@alice-i-cecile
Copy link
Member

I agree with that analysis: I didn't change it in the Stageless changes to avoid subtle bugs but it can and should be cleaned up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants