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

Use Bevy's parallel iterators rather than rayon #423

Open
dlight opened this issue Aug 26, 2023 · 5 comments
Open

Use Bevy's parallel iterators rather than rayon #423

dlight opened this issue Aug 26, 2023 · 5 comments
Labels
A-Integration very bevy specific C-Enhancement New feature or request D-Difficult Needs strong technical background, domain knowledge, or impacts are high, needs testing... P-Low S-not-started Work has not started

Comments

@dlight
Copy link

dlight commented Aug 26, 2023

Rapier uses Rayon's parallel iterators to parallelize the engine (through the macros par_iter! and par_iter_mut!, which either calls .iter() or .par_iter() (or the mutable equivalents).

But Bevy also has parallel iterators: Query has .par_iter() and .par_iter_mut() and it uses Bevy's own runtime to parallelize the queries.

Are there plans to make use of this?

A potential issue is that QueryParIter oddly doesn't implement Iterator. In this example one sees that it's expected to write

sprites
        .par_iter_mut()
        .for_each(|(mut transform, velocity)| {
            transform.translation += velocity.extend(0.0);
        });

Rather than

for (mut transform, velocity) in sprites.par_iter_mut() {
    transform.translation += velocity.extend(0.0);
};

Which I don't know why exactly; but other than that, it seems in principle possible to have a pluggable backend for parallel iteration.

(I opened this issue here because I think it only makes sense to expose this on bevy_rapier but maybe it should be moved to the main Rapier repository)

@Aceeri
Copy link
Contributor

Aceeri commented Oct 3, 2023

This is a bit more difficult because it'd have to be done in the rapier repo rather than here, but maybe worthwhile? It is a bit hard to tell.

@AnthonyTornetta
Copy link
Contributor

Something like this would have to be behind a feature flag - my game makes heavy use of async task pools to the point where using par_iter in a normal system is nearly always slower than a normal iter.

@dlight
Copy link
Author

dlight commented Nov 6, 2023

Now that's interesting. Do you know why this happens? Why is rayon's threadpool faster in this case?

@AnthonyTornetta
Copy link
Contributor

AnthonyTornetta commented Nov 17, 2023

@dlight It's not that one thread pool is faster than another's, I'm just using a lot of threads so adding even more will just hurt performance instead of help it.

Edit: I just realized I completely misread the issue. I thought you were saying to add more par_iters not switch them to bevy's. Please disregard my comments =)

@Vrixyz Vrixyz added D-Difficult Needs strong technical background, domain knowledge, or impacts are high, needs testing... P-Low S-not-started Work has not started A-Integration very bevy specific labels May 23, 2024
@Vrixyz
Copy link
Contributor

Vrixyz commented May 23, 2024

This kind of change would need quite thorough performance comparison, both for high and low amount of objects, as well as contention test (when other systems are running)

@Vrixyz Vrixyz added the C-Enhancement New feature or request label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Integration very bevy specific C-Enhancement New feature or request D-Difficult Needs strong technical background, domain knowledge, or impacts are high, needs testing... P-Low S-not-started Work has not started
Projects
None yet
Development

No branches or pull requests

4 participants