bevy_render: Batch insertion for prepare_uniform_components (#4179)

# Objective

- Make insertion of uniform components faster

## Solution

- Use batch insertion in the prepare_uniform_components system
- Improves `many_cubes -- sphere` from ~42fps to ~43fps


Co-authored-by: François <mockersf@gmail.com>
This commit is contained in:
Robert Swain 2022-03-11 23:20:18 +00:00
parent 5af746457e
commit 0e821da704

View file

@ -111,14 +111,19 @@ fn prepare_uniform_components<C: Component>(
C: AsStd140 + Clone,
{
component_uniforms.uniforms.clear();
for (entity, component) in components.iter() {
commands
.get_or_spawn(entity)
.insert(DynamicUniformIndex::<C> {
index: component_uniforms.uniforms.push(component.clone()),
marker: PhantomData,
});
}
let entities = components
.iter()
.map(|(entity, component)| {
(
entity,
(DynamicUniformIndex::<C> {
index: component_uniforms.uniforms.push(component.clone()),
marker: PhantomData,
},),
)
})
.collect::<Vec<_>>();
commands.insert_or_spawn_batch(entities);
component_uniforms
.uniforms