From ec795a20a3b6a818f73f3b431c20c0500c7f53e9 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Thu, 9 Jan 2025 22:56:36 -0800 Subject: [PATCH] Minor `TextPipeline` cleanup (#17274) # Objective Both `set_metrics` and `set_size` **can** trigger text re-layout and re-shaping, if the values provided are different form what is already in the `Buffer`. ## Solution Combine the `set_metrics` and `set_size` calls. This might be a small optimization in some situations, maybe when both font size and text bounds change in the same frame, or when spawning new text. I did measure a ~500 microsecond improvement in `text_system` for `many_buttons --respawn`, but that may have just been noise. --- crates/bevy_text/src/pipeline.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index f16fbce0dce25..dd13e5e0cbfca 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -170,8 +170,7 @@ impl TextPipeline { // Update the buffer. let buffer = &mut computed.buffer; - buffer.set_metrics(font_system, metrics); - buffer.set_size(font_system, bounds.width, bounds.height); + buffer.set_metrics_and_size(font_system, metrics, bounds.width, bounds.height); buffer.set_wrap( font_system,