geotiff: parallelise tile decode in _fetch_decode_cog_http_tiles (#1980)#1981
Merged
brendancol merged 2 commits intoMay 16, 2026
Conversation
The HTTP COG read path fetches tiles concurrently via ``read_ranges_coalesced`` (xarray-contrib#1480, xarray-contrib#1487) and then decoded them sequentially in a Python for-loop. Local ``_read_tiles`` already parallelises decode via ``ThreadPoolExecutor`` whenever ``tile_pixels >= 64 * 1024`` and ``n_tiles > 1`` (see _reader.py:2017); the HTTP path was structurally similar but never adopted the same gate, so wide windowed COG reads with many tiles left deflate/zstd decoding single-threaded after a parallel fetch. Mirror the local-file path's threshold and pool here. Codec extensions release the GIL inside their C implementations, so a ``ThreadPoolExecutor`` overlaps decode work across cores. The placement loop that writes pixels into ``result`` stays serial to avoid contended writes. Pass 10 of the geotiff performance sweep. Tests in test_cog_http_parallel_decode_2026_05_15.py: - parallel-branch end-to-end correctness (deflate, tile_size=256) - serial-branch end-to-end correctness (tile_size=128, single tile) - ThreadPoolExecutor instantiation above the threshold - single-tile path skips the decode pool - _decode_strip_or_tile invoked exactly once per placement
6850a61 to
59ca288
Compare
…e paths Review nits on the parallel-HTTP-decode change: - Extract the 64K-pixel cutoff into a module-level _PARALLEL_DECODE_PIXEL_THRESHOLD constant. The same magic number lived in _read_tiles and _fetch_decode_cog_http_tiles; the only docstring describing why it was chosen sat next to the local path. - Lift _decode_one out of the parallel branch in _fetch_decode_cog_http_tiles so the serial fallback calls the same helper instead of inlining a duplicate _decode_strip_or_tile call. Mirrors how _read_tiles defines _decode_one once and reuses it for both paths. - Drop the ThreadPoolExecutor-as-_Pool alias for parity with the local path, which imports ThreadPoolExecutor by its real name. No behaviour change. Existing 268 COG/HTTP and 734 tile/reader tests still pass; the 6 pre-existing failures (predictor2 big-endian GPU, tile_size=4 validator) predate this PR per the prior sweep notes.
Contributor
Author
PR Review: geotiff: parallelise tile decode in
|
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
forloop. The sibling local-file path in the same module (_read_tiles) already parallelises decode whenevertile_pixels >= 64 * 1024andn_tiles > 1; the HTTP path was structurally similar but never adopted the same gate.ThreadPoolExecutorin_fetch_decode_cog_http_tiles. Codec extensions (deflate, zstd, LZW) release the GIL inside their C implementations, so the pool overlaps decode work across cores. The placement loop that writes pixels intoresultstays serial to avoid contended writes.test_cog_http_parallel_decode_2026_05_15.py: parallel + serial round-trip correctness, structural pool-instantiation check above the threshold, single-tile path skips the decode pool,_decode_strip_or_tilecall count ==n_tiles.Pass 10 of /sweep-performance on the geotiff module. Closes #1980.
Test plan
python -m pytest xrspatial/geotiff/tests/test_cog_http_parallel_decode_2026_05_15.py.python -m pytest xrspatial/geotiff/tests/ -k 'cog or http'-> 262 passed.test_predictor2_big_endian_gpu_1517,test_size_param_validation_gpu_vrt_1776::test_tile_size_positive_works) flagged in prior sweep notes.