Skip to content

Commit 785d5e9

Browse files
authored
Parallelize mark_meshes_as_changed_if_their_materials_changed. (#23103)
This tiny system loops over all instances and can actually show up in the profile when the instance count reaches the millions. This PR fixes that. The `mark_meshes_as_changed_if_their_materials_changed` system in `many_cubes --no-cpu-culling --instance-count 3000000` (with PR #23101 applied) goes from 2.92 ms per frame to 0.669 ms per frame with this patch applied, a 4.4x speedup. Before and after: <img width="2756" height="1800" alt="Screenshot 2026-02-21 143243" src="https://github.com/user-attachments/assets/556b0ca2-28e8-4f01-960a-57690ab54fb4" />
1 parent b681681 commit 785d5e9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

crates/bevy_pbr/src/material.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,9 @@ fn mark_meshes_as_changed_if_their_materials_changed<M>(
654654
) where
655655
M: Material,
656656
{
657-
for mut mesh in &mut changed_meshes_query {
657+
changed_meshes_query.par_iter_mut().for_each(|mut mesh| {
658658
mesh.set_changed();
659-
}
659+
});
660660
}
661661

662662
/// Fills the [`RenderMaterialInstances`] resources from the meshes in the

0 commit comments

Comments
 (0)