Skip to content

Add memory guard for proximity line-sweep dask path#1113

Merged
brendancol merged 2 commits intoissue-1110from
issue-1111
Mar 31, 2026
Merged

Add memory guard for proximity line-sweep dask path#1113
brendancol merged 2 commits intoissue-1110from
issue-1111

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

Context

Found during performance sweep triage (#1111). The default max_distance=np.inf with scipy installed routes to the memory-safe KDTree path, so the initial "every dask user OOMs" assessment was overstated. The OOM risk is real for GREAT_CIRCLE or when scipy is missing, and those paths already had guards (lines 1309-1324). This adds an additional guard in _process_dask for the general line-sweep case.

Test plan

  • test_proximity_dask_inf_distance_memory_guard -- verifies MemoryError raised for GREAT_CIRCLE with tight memory

When max_distance >= raster diagonal, the line-sweep algorithm rechunks
the entire array into a single chunk. Add a memory estimate check
(~35 bytes/pixel working memory) that raises ValueError before the
rechunk if the working set would exceed 80% of available RAM.
When max_distance >= raster diagonal and the non-KDTree path is used
(GREAT_CIRCLE metric or no scipy), the line-sweep rechunks to a single
chunk. The existing memory guard already catches this for the
GREAT_CIRCLE case. Add a pre-rechunk estimate (~35 bytes/pixel) to
_process_dask for the general case, raising ValueError before the
rechunk if working memory would exceed 80% of available RAM.

The EUCLIDEAN/MANHATTAN + scipy path uses the memory-safe KDTree and
already has its own guards.
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 31, 2026
@brendancol brendancol merged commit 6febf40 into issue-1110 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