From a3b378fd66342ecf9a44f814acf1b18a49a05c42 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sun, 14 Dec 2025 21:52:39 +0100 Subject: lazily load tile in blit_nonzero In the benchmarks, this gives a quite good speed increase, but in real-life workloads, the speedup is not as stark (from ~66s to ~61s here). What is maybe a neat secondary effect here is that we don't end up with empty tiles, as we only allocate (in tile_mut) when there is a nonzero pixel to blit. This decreases the number of saved tiles, especially on larger zooms. --- hittekaart/src/layer.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hittekaart/src/layer.rs b/hittekaart/src/layer.rs index 0ab1975..1c860ad 100644 --- a/hittekaart/src/layer.rs +++ b/hittekaart/src/layer.rs @@ -102,7 +102,7 @@ impl TileLayer

{ let source_height = u64::from(source.height()); for tx in x / TILE_WIDTH..=(x + source_width) / TILE_WIDTH { for ty in y / TILE_HEIGHT..=(y + source_height) / TILE_HEIGHT { - let tile = self.tile_mut(tx, ty); + let mut tile = None; let offset_x = (tx * TILE_WIDTH).saturating_sub(x); let offset_y = (ty * TILE_HEIGHT).saturating_sub(y); let local_min_x = x.saturating_sub(tx * TILE_WIDTH); @@ -115,8 +115,13 @@ impl TileLayer

{ let pixel = source .get_pixel(source_x.try_into().unwrap(), source_y.try_into().unwrap()); if pixel.channels() != zero.channels() { - *tile.get_pixel_mut(x.try_into().unwrap(), y.try_into().unwrap()) = - *pixel; + if tile.is_none() { + tile = Some(self.tile_mut(tx, ty)); + } + tile.iter_mut().for_each(|t| { + *t.get_pixel_mut(x.try_into().unwrap(), y.try_into().unwrap()) = + *pixel; + }); } } } -- cgit v1.2.3