Skip to content

Commit

Permalink
bevy_render: Batch insertion for prepare_uniform_components (bevyengi…
Browse files Browse the repository at this point in the history
…ne#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>
  • Loading branch information
2 people authored and ItsDoot committed Feb 1, 2023
1 parent e699584 commit 47800c5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions crates/bevy_render/src/render_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 47800c5

Please sign in to comment.