Skip to content

Commit fb7ac3a

Browse files
james7132alradish
authored andcommitted
Optimize color computation in prepare_uinodes (bevyengine#7311)
# Objective Speed up `prepare_uinodes`. The color `[f32; 4]` is being computed separately for every vertex in the UI, even though the color is the same for all 6 verticies. ## Solution Avoid recomputing the color and cache it for all 6 verticies. ## Performance On `many_buttons`, this shaved off 33% of the time in `prepare_uinodes` (7.67ms -> 5.09ms) on my local machine. ![image](https://user-images.githubusercontent.com/3137680/213862448-236ac6e4-040a-4c86-a801-b947d99cc581.png)
1 parent de1d950 commit fb7ac3a

File tree

1 file changed

+2
-1
lines changed
  • crates/bevy_ui/src/render

1 file changed

+2
-1
lines changed

crates/bevy_ui/src/render/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,12 @@ pub fn prepare_uinodes(
523523
uvs = [uvs[3], uvs[2], uvs[1], uvs[0]];
524524
}
525525

526+
let color = extracted_uinode.background_color.as_linear_rgba_f32();
526527
for i in QUAD_INDICES {
527528
ui_meta.vertices.push(UiVertex {
528529
position: positions_clipped[i].into(),
529530
uv: uvs[i].into(),
530-
color: extracted_uinode.background_color.as_linear_rgba_f32(),
531+
color,
531532
});
532533
}
533534

0 commit comments

Comments
 (0)