Skip to content

Fix balanced_allocation OOM: lazy source extraction + memory guard#1115

Merged
brendancol merged 5 commits into
masterfrom
issue-1114
Mar 31, 2026
Merged

Fix balanced_allocation OOM: lazy source extraction + memory guard#1115
brendancol merged 5 commits into
masterfrom
issue-1114

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

@brendancol brendancol commented Mar 31, 2026

Summary

  • _extract_sources now uses da.unique() for dask arrays instead of materializing the full raster to find source IDs
  • Add memory guard before computing N cost surfaces: estimates N * array_bytes + overhead and raises MemoryError if it would exceed 80% of available RAM

Context

Found during performance sweep triage (#1114). The algorithm is inherently O(N * array_size) in memory since it holds N cost-distance surfaces simultaneously. This can't be fundamentally fixed without a different algorithm, but the guard catches it early with a clear message instead of letting the system OOM mid-computation.

Test plan

  • test_balanced_allocation_memory_guard -- verifies MemoryError raised when available memory is insufficient
  • test_extract_sources_dask_no_materialize -- verifies da.unique() used for dask source extraction

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.
…1114)

- _extract_sources now uses da.unique() for dask arrays instead of
  materializing the full raster to find source IDs
- Add memory guard before computing N cost surfaces: estimates
  N * array_bytes + overhead and raises MemoryError if it would
  exceed 80% of available RAM
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Mar 31, 2026
@brendancol brendancol merged commit ca8825a into master Mar 31, 2026
11 checks passed
@brendancol brendancol deleted the issue-1114 branch May 4, 2026 13:07
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