bevy/crates/bevy_ecs/src/system
James Liu 88b353c4b1 Reduce the use of atomics in the render phase (#7084)
# Objective
Speed up the render phase of rendering. An extension of #6885.

`SystemState::get` increments the `World`'s change tick atomically every time it's called. This is notably more expensive than a unsynchronized increment, even without contention. It also updates the archetypes, even when there has been nothing to update when it's called repeatedly.

## Solution
Piggyback off of #6885. Split `SystemState::validate_world_and_update_archetypes` into `SystemState::validate_world` and `SystemState::update_archetypes`, and make the later `pub`. Then create safe variants of `SystemState::get_unchecked_manual` that still validate the `World` but do not update archetypes and do not increment the change tick using `World::read_change_tick` and `World::change_tick`. Update `RenderCommandState` to call `SystemState::update_archetypes` in `Draw::prepare` and `SystemState::get_manual` in `Draw::draw`.

## Performance
There's a slight perf benefit (~2%) for `main_opaque_pass_3d` on `many_foxes` (340.39 us -> 333.32 us)

![image](https://user-images.githubusercontent.com/3137680/210643746-25320b98-3e2b-4a95-8084-892c23bb8b4e.png)

## Alternatives
We can change `SystemState::get` to not increment the `World`'s change tick. Though this would still put updating the archetypes and an atomic read on the hot-path.

---

## Changelog
Added: `SystemState::get_manual`
Added: `SystemState::get_manual_mut`
Added: `SystemState::update_archetypes`
2023-01-18 02:19:19 +00:00
..
commands Fix beta clippy lints (#7154) 2023-01-11 09:51:22 +00:00
exclusive_function_system.rs Add bevy_ecs::schedule_v3 module (#6587) 2023-01-17 01:39:17 +00:00
exclusive_system_param.rs Relax Sync bound on Local<T> as ExclusiveSystemParam (#7040) 2023-01-09 20:56:06 +00:00
function_system.rs Reduce the use of atomics in the render phase (#7084) 2023-01-18 02:19:19 +00:00
mod.rs Added Ref to allow immutable access with change detection (#7097) 2023-01-11 15:41:54 +00:00
query.rs Make Query fields private (#7149) 2023-01-10 18:55:23 +00:00
system.rs Add bevy_ecs::schedule_v3 module (#6587) 2023-01-17 01:39:17 +00:00
system_param.rs Add a missing impl of ReadOnlySystemParam for Option<NonSend<>> (#7245) 2023-01-17 03:29:08 +00:00
system_piping.rs Add bevy_ecs::schedule_v3 module (#6587) 2023-01-17 01:39:17 +00:00