perf: speed up backed sparse integer indexing#2506
Open
tippered1-debug wants to merge 2 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2506 +/- ##
==========================================
- Coverage 87.61% 85.71% -1.91%
==========================================
Files 49 49
Lines 7693 7719 +26
==========================================
- Hits 6740 6616 -124
- Misses 953 1103 +150
|
ilan-gold
reviewed
Jun 23, 2026
ilan-gold
left a comment
Contributor
There was a problem hiding this comment.
Can this reuse subset_by_major_axis_mask? It looks eerily familiar. Or could that method be removed in favor of this code path? I'm not sure what the performance considerations here are but I think they are probably trivial i.e., operations on a small 1d array.
Thanks for the contribution!
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.
Summary
Integer indexing of backed sparse datasets currently reads every selected row or column separately, even when most of the indices form contiguous runs.
This PR groups those runs and reads them as slices. Shuffled indices and duplicates are restored to their original order after reading. Highly fragmented indexers continue to use the existing path, since slicing does not help in that case.
Related to #1224.
Benchmark
Benchmarked on a
10000 x 10000sparse matrix with density0.01. Each indexer contains2048elements. Results are medians of three runs.HDF5 CSR
7.10 ms→0.73 ms— 9.7x faster6.81 ms→0.74 ms— 9.2x faster7.04 ms→1.03 ms— 6.8x faster7.02 ms→0.83 ms— 8.5x fasterZarr CSR
16.60 ms→3.70 ms— 4.5x faster16.27 ms→13.92 ms— 1.2x faster18.91 ms→14.30 ms— 1.3x faster19.19 ms→8.53 ms— 2.2x fasterFragmented indexers continue to use the existing path and stayed close to the previous timings.