Fix reproject.merge same-CRS dask path materializing full source per chunk#1576
Open
brendancol wants to merge 1 commit intomainfrom
Open
Fix reproject.merge same-CRS dask path materializing full source per chunk#1576brendancol wants to merge 1 commit intomainfrom
brendancol wants to merge 1 commit intomainfrom
Conversation
…chunk `_merge_block_adapter` called `src_data.compute()` on the full source dask array for every output chunk on the same-CRS direct-placement path. For a 256x256 source split into 32x32 output chunks, this materialized 8.9M pixels for 131K source pixels (68x amplification). At realistic 8192x8192 source with 256x256 output chunks the amplification would push driver-side data flow into terabyte territory. The fix adds `_place_same_crs_lazy` that mirrors `_place_same_crs` but slices the source window first and only calls `.compute()` on that slice. Post-fix ratio is 1.00x (131K pixels materialized for 131K source). Mirrors the slicing pattern already in `_reproject_chunk_numpy` and `_reproject_chunk_cupy`. Adds regression test `test_merge_dask_same_crs_bounded_materialization` that traces `da.Array.compute()` calls and asserts total materialized pixels stay under 3x total source size. Surfaced by the 2026-05-10 reproject performance sweep. Closes #1571.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_merge_block_adaptercalledsrc_data.compute()on the full sourcedask array for every output chunk on the same-CRS direct-placement
path. Measured: 256x256 source with 32x32 output chunks materialized
8.9M pixels for 131K source pixels (68x amplification). For an
8192x8192 source with 256x256 output chunks, the amplification would
push driver-side data flow into terabyte territory.
The fix adds
_place_same_crs_lazy(xrspatial/reproject/init.py)which mirrors
_place_same_crsbut slices the source window first andcalls
.compute()only on that slice. Post-fix amplification is 1.00x.Mirrors the slicing pattern already in
_reproject_chunk_numpyand_reproject_chunk_cupy.Surfaced by the 2026-05-10 reproject performance sweep.
Closes #1571.
Test plan
test_merge_dask_same_crs_bounded_materializationtracesda.Array.compute()calls and asserts total materialized pixels stay under 3x total source size.test_merge_dask_same_crs_matches_eagercontinues to pass (bit-equal placement preserved).