Skip to content

Commit 7495d68

Browse files
authored
UI materials: don't reserve in loop when enough capacity (#15919)
# Objective - UI materials reserve too much capacity in a vec: for every node in the transparent phase, it reserves enough memory to store all the nodes - Update #10437 ## Solution - Only reserve extra memory if there's not enough - Only reserve the needed memory, not more
1 parent ad9f197 commit 7495d68

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

crates/bevy_ui/src/render/ui_material_pipeline.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,11 @@ pub fn queue_ui_material_nodes<M: UiMaterial>(
642642
bind_group_data: material.key.clone(),
643643
},
644644
);
645-
transparent_phase
646-
.items
647-
.reserve(extracted_uinodes.uinodes.len());
645+
if transparent_phase.items.capacity() < extracted_uinodes.uinodes.len() {
646+
transparent_phase.items.reserve_exact(
647+
extracted_uinodes.uinodes.len() - transparent_phase.items.capacity(),
648+
);
649+
}
648650
transparent_phase.add(TransparentUi {
649651
draw_function,
650652
pipeline,

0 commit comments

Comments
 (0)