dimforge / dimforge/bevy_rapier
Use Bevy's parallel iterators rather than rayon
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 282
- PR merge metrics
- No merged PRs in 30d
Description
Rapier uses Rayon's parallel iterators to parallelize the engine (through the macros [`par_iter!` and `par_iter_mut!`](https://github.com/dimforge/rapier/blob/958fba8ed43328e7e33bb9585a735577fa1061e1/src/lib.rs#L70-L90), which either calls `.iter()` or `.par_iter()` (or the mutable equivalents).
But Bevy also has parallel iterators: `Query` has [`.par_iter()`](https://docs.rs/bevy/latest/bevy/ecs/query/struct.QueryState.html#method.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`](https://docs.rs/bevy/latest/bevy/ecs/query/struct.QueryParIter.html) oddly doesn't implement `Iterator`. In [this example](https://github.com/bevyengine/bevy/blob/365cf3114a8756f3fcc7e1d783df01a079bc6e0c/examples/ecs/parallel_query.rs#L36-L41) one sees that it's expected to write
```rust
sprites
.par_iter_mut()
.for_each(|(mut transform, velocity)| {
transform.translation += velocity.extend(0.0);
});
```
Rather than
```rust
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)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.