Skip to content

Add memory guard to cost_distance iterative Dijkstra + da.block assembly#1119

Merged
brendancol merged 4 commits intomasterfrom
issue-1118
Mar 31, 2026
Merged

Add memory guard to cost_distance iterative Dijkstra + da.block assembly#1119
brendancol merged 4 commits intomasterfrom
issue-1118

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

@brendancol brendancol commented Mar 31, 2026

Summary

  • Add memory guard before _preprocess_tiles: estimates ~3x dataset size and raises MemoryError if it would exceed 80% of available RAM, suggesting finite max_cost
  • Replace np.concatenate result assembly with da.block to avoid building a monolithic numpy array from tile results

Context

Found during performance sweep triage (#1118). The iterative tiled Dijkstra path (triggered when max_cost=inf or implied radius > chunk dimensions) caches all tiles in RAM via dask.compute(*blocks). The _assemble_result then np.concatenated everything into a single numpy array. At 30TB both are fatal.

The da.block change means the assembled result stays as a dask array with proper chunk structure, avoiding the second full materialization.

Test plan

  • All 44 existing cost_distance tests pass (verified)

Parallel subagent triage + ralph-loop workflow for auditing all
xrspatial modules for performance bottlenecks, OOM risk under
30TB dask workloads, and backend-specific anti-patterns.
7 tasks covering command scaffold, module scoring, parallel subagent
dispatch, report merging, ralph-loop generation, and smoke tests.
…1118)

- Add memory guard before _preprocess_tiles: estimates ~3x dataset
  (source + friction cache + result) and raises MemoryError if it
  would exceed 80% of available RAM, suggesting finite max_cost.
- Replace np.concatenate assembly with da.block to avoid building a
  monolithic numpy array from tile results. Tiles are now wrapped in
  dask.delayed and assembled lazily.
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 31, 2026
@brendancol brendancol merged commit 1d60fbd into master Mar 31, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant