-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Make Task
s functional on WASM
#13889
Conversation
@kettle11 can I get your review here please? |
I don't agree that this is contentious, it's just finishing an incomplete feature. The considerations here are in terms of implementation details, not direction IMO |
This conceptually looks fine to me, but @JoJoJet have you checked that this still runs with the This PR has instructions for how to build with that enabled: #12205 That PR enabled Bevy Wasm to compile with threading enabled and make use of other libraries to spawn threads, parallelize, etc. even if Bevy Wasm itself isn't yet threaded internally. |
I haven't tested that functionality yet but I see no reason it would stop working. I'm hoping that with this PR, full multi-threading support will just be a drop-in addition that utilizes this same interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only some documentation nits. I don't feel qualified to comment on the correctness of the implementation.
Co-authored-by: Jan Hohenheim <[email protected]>
(Below copied from performance.md) - Multithreading, fix dirty chunks - Fix for dirty chunks was to check if a chunk was empty or not before updating, this gave most performance gains (to around 35-45us while few updates are happening) - Multithreading implementation using [bevy_tasks](https://docs.rs/bevy_tasks/latest/bevy_tasks/index.html), specifically the `ComputeTaskPool` - No sand: 35us mean - Drawing lots of sand at one: still around 490us - Some constant movement in a few chunks such as water/smoke: 270us Multithreading should help most when the world and chunk size gets much bigger. Currently multithreading is only implemented in one spot (simulating a chunk), but I want to use the taskpool for other things in the future such as: - Creating the dirty rectangles of chunks that need updating after simulation while still in thread (will probably need to use a threadsafe hashmap and/or mutexes) - Updating the render image after simulation while in the thread, currently the whole image is created each frame and is a slow point, but we could just update chunks that have changed - Creating the colliders for each chunk, this should also not recreate colliders for chunks that haven't changed, collider generation is currently the slowest part of the simulation > Note on multithreading on web (WASM) > Currently bevy does not support multithreaded execution on WASM builds, and the `bevy_tasks` module does not support multithreading. > However, `bevy_tasks` support for web [is merged and due for bevy 0.15 (next release)](bevyengine/bevy#13889) > The project still works on WASM but this means performance is abit slower than native, optimizations from the dirty chunk system still help a lot
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1660 if you'd like to help out. |
Objective
Right not bevy's task pool abstraction is kind of useless on wasm, since it returns a
FakeTask
which can't be interacted with. This is only good for fire-and-forget it tasks, and isn't even that useful since it's just a thin wrapper aroundwasm-bindgen-futures::spawn_local
Solution
Add a simple
Task<T>
handler type to wasm targets that allow waiting for a task's output or periodically checking for its completion. This PR aims to give the wasm version of these tasks feature parity with the native, multi-threaded version of the taskTesting