From 759c2926bbcbb044ba9b7b700fd310d83a6441f7 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Tue, 22 Feb 2022 09:07:43 +0100 Subject: [PATCH] Don't reallocate visible sprite entities map every frame --- crates/bevy_sprite/src/render/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 1a799999d4c3b..cc5c8d2a81f17 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -359,6 +359,7 @@ pub fn queue_sprites( mut extracted_sprites: ResMut, mut views: Query<(&VisibleEntities, &mut RenderPhase)>, events: Res, + mut visible_entities_map: Local>, ) { // If an image has changed, the GpuImage has (probably) changed for event in &events.images { @@ -403,7 +404,8 @@ pub fn queue_sprites( let extracted_sprites = &mut extracted_sprites.sprites; let image_bind_groups = &mut *image_bind_groups; - let visible_entities = HashSet::from_iter(visible_entities.iter().cloned()); + visible_entities_map.clear(); + visible_entities_map.extend(visible_entities.iter().copied()); transparent_phase.items.reserve(extracted_sprites.len()); @@ -433,7 +435,7 @@ pub fn queue_sprites( // Batches are merged later (in `batch_phase_system()`), so that they can be interrupted // by any other phase item (and they can interrupt other items from batching). for extracted_sprite in extracted_sprites.iter() { - if !visible_entities.contains(&extracted_sprite.entity) { + if !visible_entities_map.contains(&extracted_sprite.entity) { continue; } let new_batch = SpriteBatch {