raster: Restrict GDAL-linked raster reads to the needed column range - #7876
raster: Restrict GDAL-linked raster reads to the needed column range#7876ninsbl wants to merge 10 commits into
Conversation
|
I don't understand the C code changes enough to approve or reject |
Thanks for looking into it anyway! |
|
If someone with knowledge of this area of the code could review this PR, I would be really glad. I am aware of time constraints of course and I would not ask if not this would be a major issue (for me). It grinds one of my use-cases for GRASS practically to a halt, because stuff that should take less thqan half a minute can take more than two hours... So, this PR would increase the performance of GRASS for my case up to more than x250-300 (depending on the input dataset and file system of course)... I assume it will also significantly improve usage of GRASS as processing backend in QGIS in many cases... |
echoix
left a comment
There was a problem hiding this comment.
Well, it doesn’t look wrong, and you’ll be the first to change it back if it doesn’t work, so here you go.
I was hoping on someone that would have known if something was missing or could be done in a better way if it existed.
Thanks! I addressed your comments and added the mentioned tests... |
|
The code changes looks reasonable to me, but I’m not totally comfortable with this part of the code, let us give @metzm a chance to chime in. |
This comment has been minimized.
This comment has been minimized.
|
@echoix just to make sure: Your AI review referenced only tests outside of this PR. Are the findings related to the changes here or to the (relativly new) ctypes based tests? |
Oh, did I mistype the PR number ? I didn't caught on since it was the same topics and touching bounds. Let me retry something. Or you could on your side too. |
Indeed, it's for #7879 |
AI-assisted review — Claude Code (Opus 5)No correctness bugs found. Reviewed Full reviewWhat was verifiedThe change is only safe if a handful of invariants hold, so each was checked against the source rather than by eye:
Findings
Notes, not findings
Method and limitsStatic review only — GRASS was not built and the new test file was not executed. The review was run by a human-directed AI agent; all findings above were traced to the cited source lines by hand. Generated by Claude Code |
read_data_gdal() - used when reading a linked-raster maps (r.external) - always reads the full native row width from the GDAL dataset, regardless of the current region.
For a raster map that is much wider than the region - e.g. a country-wide mosaic VRT built from many source tiles, this can have significant impact on the processing time. Because every row read touches every source tile across the full width, even when the region only overlaps one or two of them. The consequence is significantly degraded performance for such cases, esp. if several maps are read simultaneously e.g. in a mapcalculator expression and if data is stored on file systems with higher latency (e.g. NAS with CIFS mount).
This PR restricts the GDAL read to the native column range actually needed. It is computed from the column mapping GRASS already builds once per file open. The behavior for hflip'ed datasets is unchanged and falls back to the original full-width read.
r.in.gdal and r.external are unaffected by the changes. OpenMP parallelized tools are not affected by the change either. I do have a regression-test for that in my local working copy and can push it to the PR if it seems useful. And I am happy to remove the r.in.gdal test if that is not needed (I just wanted to make sure all possible caveats are covered).
The PR includes a pytest covering cases where the computaional region is fully inside, partially outside, and fully outside the linked file's extent. THere is also one test to verify r.in.gdal is unaffected.
Given the significant performance degradation in some cases I take the liberty to classify this as a blocker. May be also a reason to backport...
Generated with the help of AI with lots of manual debugging and verifications...