You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR addresses two performance leverages in sptial_neighbors:
extract per-library sub-matrices upfront and once (most important)
enable per-library parallelism with joblib (relatively high per-worker overhead, only worthwhile with many samples)
The first step brings down the runtime by ~50% in my real-world dataset.
Parallelism doesn't add a ton, but still slightly improves the wall time. It really depends on the dataset how much it adds, therefore I left the default at n_jobs=1.
When working with spatialdata, there's an additional bottleneck in _prepare_spatial_neighbors_input that I'll follow up on separately.
❌ Patch coverage is 71.42857% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.29%. Comparing base (da789d0) to head (d2305e3).
Thanks, extracting the spatial coords and then slicing was very much needed yes but I really doubt we need multiprocess parallelization here. We can use thread parallelisim because scikit-learn's nearest neighbor search is written in Cython/C++ and releases the GIL, therefore it will utilize the cores.
Usually the effectiveness of thread-based parallelism is limited, even in C++, because of Ahmdal's law and communication overhead. It really depends a lot on the concrete method, but it is often more effective to parallelize at the level of samples, or use a combination of process and thread-based parallelism.
"Ahmdal's law and communication overhead" these are also true for process based parallelism, and there is even more overhead on communication in processes. If we parallelize with backend=threads how different would the results here look like?
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
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.
Description
This PR addresses two performance leverages in sptial_neighbors:
The first step brings down the runtime by ~50% in my real-world dataset.
Parallelism doesn't add a ton, but still slightly improves the wall time. It really depends on the dataset how much it adds, therefore I left the default at
n_jobs=1.When working with spatialdata, there's an additional bottleneck in
_prepare_spatial_neighbors_inputthat I'll follow up on separately.How has this been tested?
Closes
no related issue