From 4bf633e8a9cb17aa94ac17d1010613f0b3bcdf98 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 28 Oct 2026 10:33:46 +0300 Subject: [PATCH] HUD paint: build the sprite key in one reused buffer paint() runs for every drawn HUD call each frame and made a fresh String per sprite to look it up in the atlas: sprite.to_string() for a mob_effect and format!("gui/sprites/{sprite}") otherwise. One buffer outside the loop keeps the same keys without the allocation. Co-Authored-By: Hermes Agent (Nous Research) --- crates/horizon-client/src/hud_layout.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/src/hud_layout.rs b/crates/horizon-client/src/hud_layout.rs index efdb2747b..0d4c75d13 100644 --- a/crates/horizon-client/src/hud_layout.rs +++ b/crates/horizon-client/src/hud_layout.rs @@ -801,6 +801,8 @@ impl HealthHud { /// nausea blits (their blending needs the screen-effect pipeline). pub fn paint(batch: &mut crate::hud::HudBatch, atlas: &crate::hud::HudAtlas, draws: &[GuiDraw]) { let mut stack = vec![IDENTITY]; + // One buffer for the sprite keys, instead of a string per drawn sprite. + let mut name = String::new(); for d in draws { let start = batch.vertices.len(); let pose = *stack.last().unwrap_or(&IDENTITY); @@ -817,12 +819,14 @@ pub fn paint(batch: &mut crate::hud::HudBatch, atlas: &crate::hud::HudAtlas, dra } => { // Effect sprites belong to the mob_effect atlas directory; // the other blitSprite ids refer to GUI sprites. - let name = if sprite.starts_with("mob_effect/") { - sprite.to_string() + name.clear(); + if sprite.starts_with("mob_effect/") { + name.push_str(sprite); } else { - format!("gui/sprites/{sprite}") - }; - let Some(mut r) = atlas.sprites.get(&name).copied() else { + name.push_str("gui/sprites/"); + name.push_str(sprite); + } + let Some(mut r) = atlas.sprites.get(name.as_str()).copied() else { continue; }; if let Some([sw, sh, u, v]) = *region {