Repository navigation
perf(data): place a decoded GeoTIFF strip or tile a row at a time - #3011
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| 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 }; |
There was a problem hiding this comment.
Hardening nit on the new run-of-a-row path. The arithmetic here is unchecked (src + width * per_pixel, and the (y - y0) as usize * stride on line 1205), while the loop below this block keeps the same kind of position math checked and says so in a comment. The values are bounded by values.len() after the shape match, so this can't overflow in practice. Using saturating arithmetic here keeps the two paths consistent and avoids a wrap in release builds if the shape logic changes later:
| let Some(src) = values.get(src..src + width * per_pixel) else { continue }; | |
| let Some(src) = values.get(src..src.saturating_add(width.saturating_mul(per_pixel))) else { continue }; |
The continue also drops a whole row without a notice if it is ever reached. The shape check above makes that unreachable, and the old per-pixel loop had the same silent skip, so this is not a regression. Returning an error here would match the "never silent" rule if you want the path to fail loudly instead.
Category: quality
There was a problem hiding this comment.
Left for the release quality pass. The shape check above the new path ties these values to the decoded chunk's own length, so the products stay within it and the row is never skipped.
Code reviewBugs: None found. I checked the new run-of-a-row path in
Confidence: high. Security: None found. The change is pure index arithmetic on data already bounded by the shape check. Performance: No new allocation or copy. The speed-up is plausible (a Quality:
AGENTS.md: No violations found.
Twins checked: The change sits in Tests: Prior reviews: The review-thread file is empty, so there are no earlier concerns to skip. Change sizeCompared with the base branch: the whole PR against main (merge base 336a178 to PR head cd42a90).
Hmm, that table is wrong. Corrected values follow.
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the |
|
@coderabbitai full review |
Action performed
|
Summary
A GeoTIFF read from a file is decoded on several threads, which take turns, behind one lock, copying each decoded strip or tile into the bands. That copy went a sample at a time, so it held the other threads up.
When every pixel is kept and there are no rounded values to count,
Chunks::placenow copies a run of a row at a time:copy_from_slicefor one sample per pixel, one strided pass per band for interleaved samples. Reads that keep every k-th pixel, and reads that count rounded values, take the old loop.In a profile of drawing the benchmark's 8.9-million-cell DEM, placing took about 45 ms of CPU, all of it under the lock. It now takes under 1 ms.
Timing
Whole
rustgis-cli run, release builds ofmain(336a178) and this change, 25 runs each with the builds taking turns, through the job queue on a shared 8-thread machine (load average about 9). Median wall and CPU time:mainlayer.addData)An earlier set of 11 runs, at 10 ms resolution, put the large load at 1.68 s and 1.48 s (1.14×), so read the factor as that range. The rest of the load is mainly decompression and the predictor, band statistics, and setting up the coordinate system.
Output
share.exportRaster(plain GeoTIFF) writes byte-identical files frommainand this change for the DEM, its COG, and copies of it that are striped, LZW, Int32, Float64, three bands interleaved by pixel or stored apart (tiled), and three Int16 bands in strips.Surfaces and memory
Every GeoTIFF read a strip or tile at a time takes this path: desktop, command line, Python, browser and phone (one thread in the browser, with the same cheaper copy). No new allocation and no copy of layer data. Nothing saved changes.
Testing
decimation_keeps_the_same_pixels_whatever_the_chunk_shapealready covers the new path at k = 1: several chunk shapes, padded or not, two samples a pixel, whole grids and parts of them.cargo fmt --all --checkpassed.UI evidence
No visible UI change.
Related issue
Part of #1227.
Summary by CodeRabbit