fishfolk / jumpy

Tactical 2D shooter in fishy pixels style. Made with Rust-lang 🦀 and Bevy 🪶
https://fishfolk.org/games/jumpy/
Other
1.67k stars 123 forks source link

Performance: bevy_simple_tilemap uses Rayon parallel iterators causing substantial performance issues #841

Closed MaxCWhitehead closed 1 year ago

MaxCWhitehead commented 1 year ago

Description

I have consistently seen hitches in extract_tilemaps system in bevy_simple_tilemap. I dug into this as it seems like it should be a very straightforward function, just looping and math. It turns out when iterating over tiles, it is using 'par_iter', which seems to be Rayon's implementation of a magic parallel loop.

Issues with magic parallel loops are pretty common,I didn't look into what it's doing, but sometimes we get 10ms hitches here. Probably overhead spinning up a large amount of tasks, cache missing, copying all the data to other threads, etc.

Below is a screenshot of histogram of this scope with and without this par_iter call. Yellow is without, red is with. Will probably open an issue/PR with bevy_simple_tilemap on this, would be good to get this behind a feature flag, or have it off by default.

image
zicklag commented 1 year ago

Good find! I think having a feature flag in bevy_simple_tilemap for rayon makes sense. It's already avoiding rayon on WASM targets, so it should be an extremely simple change to parameterize it for a feature as well.

MaxCWhitehead commented 1 year ago

I opened a PR adding this feature flag in bevy_simple_tilemap, if this is merged / released we can disable this.