Bad performance with ECS
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
f4776f2
## Operating system & version
Ex: Manjaro & EMUI 10 (Huawei P40 lite)
## What you did
Each frame (60 per / second):
* Iterate over 400 entities
* Add ~ 400 components
* Remove ~ 400 components
I tried to integrate bevy_ecs into my engine (with miniquad as renderer), so my code is looking like that:
```rs
// initialization
let mut schedule = Schedule::default();
let mut update = SystemStage::parallel();
update.add_system(draw_system);
schedule.add_stage("update", update);
// game loop
world.insert_non_send(game);
schedule.run(world);
let game = world.remove_non_send::()
// system
fn draw_system(
mut game: NonSendMut,
camera_view: Res,
query: Query<&components::Sprite>,
) {
// ..
for sprite in query.iter() {
// there I check if sprite is inside camera view or outside and add/remove corresponding marker components
}
// ..
}
```
## What you expected to happen
This should take around 0.1ms - 0.2ms on PC and 0.3ms - 0.6ms on android
## What actually happened
`i7-8650u` - Manjaro Linux - Power Save mode
Without sparse-storage ~ 0.7 - 0.8ms
With sparse-storage (only for marker component) ~ 0.6ms
`Kirin 810` - EMUI 10 - Huawei P40 Lite - Normal mode
Without sparse storage ~ 2.5ms
With sparse-storage (only for marker component) ~ 1.5ms
More values from my phone:
* Start frame ~ 0.0
* Create & render debugging ImgUI ~ 0.7ms - 0.8ms
* Inject Renderer & Game data into World
* Run Single System with one render pass ~ 1.2 - 1.4ms
* Delete / Add components ~ 3ms - 4ms <----- for some reason this step takes too long
* Remove Renderer & Game data from World
## Additional information
Only scheduling & running 1 system per frame with bevy_ecs on my phone takes 0.2ms :(
Contributor guide
Assessment
This issue has not been assessed yet.