Speed up cost_distance iterative tile Dijkstra 2-4x#1023
Merged
brendancol merged 1 commit intomasterfrom Mar 18, 2026
Merged
Conversation
Batch-compute all dask tiles in a single scheduler pass and cache them for reuse across iterations, replacing per-tile .compute() calls that re-executed the dask graph each time. Store friction boundaries as float64 to skip repeated dtype conversion. Assemble the final result eagerly from cached tiles instead of through da.map_blocks. Pass precomputed f_min from dask+cupy fallback to avoid a redundant da.nanmin().compute(). Benchmarked improvement on the iterative (unbounded max_cost) path: 200x100: 0.206s -> 0.050s (4.1x), 1.90MB -> 0.80MB (-58%) 300x150: 0.229s -> 0.075s (3.0x), 2.91MB -> 1.38MB (-53%) 400x200: 0.263s -> 0.114s (2.3x), 4.02MB -> 2.19MB (-46%) numpy and dask-bounded (map_overlap) paths are unchanged.
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
dask.compute()call and cache them, replacing per-tile.compute()calls that re-executed the graph on every iterationda.map_blocks_compute_seedsf_minfrom the dask+cupy fallback path to_cost_distance_dask, avoiding a redundantda.nanmin().compute()Benchmarked improvement on the iterative (unbounded
max_cost) dask path:numpy and dask-bounded (
map_overlap) paths are unchanged.Test plan
test_cost_distance.pytests pass_f_mincorrectly (requires GPU)