From cd42a902204a28e8b24b34bb0c3779abdb172143 Mon Sep 17 00:00:00 2001 From: mavrick Date: Wed, 25 Nov 2026 22:02:30 -0600 Subject: [PATCH] perf(data): place a decoded strip or tile a row at a time (#1227) Threads reading a GeoTIFF take turns placing the chunks they decode, and each chunk was placed a sample at a time. With every pixel kept and no rounded values to count, copy whole runs of a row instead. --- crates/data/src/raster/geotiff.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/data/src/raster/geotiff.rs b/crates/data/src/raster/geotiff.rs index 14ec9e0968..9d84fb1315 100644 --- a/crates/data/src/raster/geotiff.rs +++ b/crates/data/src/raster/geotiff.rs @@ -1197,6 +1197,28 @@ impl Chunks { })?; let ((xs, xe), (ys, ye)) = (span.kept(span.cols, x0, cols, k), span.kept(span.rows, y0, rows, k)); let (sc, sr) = (u64::from(span.cols.0), u64::from(span.rows.0)); + // Every pixel kept and none to count: a run of a row at a time. Threads reading an image + // take turns placing their chunks, so this part of a read isn't shared among them. + if k == 1 && changed.is_none() { + let (width, left) = (xe.saturating_sub(xs) as usize, (xs - x0) as usize); + for y in ys..ye { + let src = ((y - y0) as usize * stride + left) * per_pixel; + let dst = (y - sr) as usize * ow + (xs - sc) as usize; + let Some(src) = values.get(src..src + width * per_pixel) else { continue }; + for b in 0..self.samples { + let band = if self.planar { plane } else { b }; + let Some(row) = bands.get_mut(band).and_then(|v| v.get_mut(dst..dst + width)) else { continue }; + if per_pixel == 1 { + row.copy_from_slice(src); + } else { + for (slot, v) in row.iter_mut().zip(src.iter().skip(b).step_by(per_pixel)) { + *slot = *v; + } + } + } + } + return Ok(()); + } let mut y = ys; while y < ye { let mut x = xs;