Hoist proximity line-sweep kernel to module level to stop per-call recompiles (#3103)#3126
Merged
Merged
Conversation
brendancol
commented
Jun 9, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
Review
Blockers
None.
Suggestions
None.
Nits
xrspatial/tests/test_proximity.py(new test at end of file): the regression test relies on numba'sDispatcher.signaturesattribute. It has been stable for years, but if numba ever drops it the test will fail with an AttributeError rather than a clear message. Fine to leave as is; noting it for the record.
What was checked
- Extracted the old closure body from HEAD~1, dedented it, and diffed against the new module-level kernel: exact match. The only code changes are the signature, the
_process_numpycall site, and one comment. - The former closure variables became arguments with the same runtime values (
np.float64(max_distance)matches the captured float;target_valuesis the samenp.asarrayresult), so numerical behavior is unchanged. - All 411 proximity tests pass on a CUDA host, covering numpy/cupy/dask+numpy/dask+cupy parity, tie-breaking, and metric validation.
- Measured effect matches the issue: warm 10x10 call 0.44s -> ~1ms, 1000x1000 0.49s -> ~35ms, and the dispatcher holds a single signature across repeated calls.
- The regression test pins the fix structurally (signature-count stability) instead of a flaky wall-clock bound.
- Benchmark already exists at
benchmarks/benchmarks/proximity.py; no API or backend-support change, so README and docs need no update.
…e-proximity-2026-06-09-01 # Conflicts: # xrspatial/tests/test_proximity.py
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.
Closes #3103
_process_numpy_linesweepfrom a closure inside_processto module level. The former closure variables (target_values,max_distance,distance_metric,process_mode) are now arguments, so numba compiles once per signature and reuses it across calls instead of recompiling the kernel on everyproximity()call._process_numpy.proximity()calls don't grow the dispatcher's signature list.Warm-call timings on the numpy backend: 10x10 raster 0.44s -> ~1ms, 1000x1000 raster 0.49s -> ~35ms. The ~0.42s constant was recompilation, not compute.
Backend coverage: numpy and dask+numpy are the affected paths (the line-sweep only runs in PROXIMITY mode with EUCLIDEAN/MANHATTAN). cupy and dask+cupy are untouched but their parity tests were run.
Test plan:
pytest xrspatial/tests/test_proximity.py— 411 passed on a CUDA host (cupy and dask+cupy parity tests included)test_proximity_linesweep_compiled_onceguards the module-level dispatcher