Avoid diff allocation for integer range indices#3014
Open
KookiesNKareem 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 #3014 +/- ##
===========================================
- Coverage 68.16% 43.44% -24.73%
===========================================
Files 109 223 +114
Lines 11779 31598 +19819
===========================================
+ Hits 8029 13727 +5698
- Misses 3750 17871 +14121 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
This PR adds range-specific fast paths for integer
OrdinalRangeindices when Reactant checks slice stride and index contiguity.The existing generic fallback calls
diff(x), which materializes an O(n) vector just to inspect the stride/contiguity of ranges such as1:n,1:2:n, and colon-derivedBase.Slice(Base.OneTo(n)). Integer ordinal ranges already expose this information throughstep(x), so these checks can be O(1) and allocation-free.The change is deliberately narrow:
OrdinalRange{<:Integer,<:Integer}get_slice_stride(1:0) == -1get_slice_stride(1:1) == 1Base.Slice(Base.OneTo(n))indicesBenchmark evidence
Measured on NVIDIA TITAN RTX with Reactant loaded:
Validation
Added focused regression coverage in
test/core/indexing.jlfor:Base.Slice(Base.OneTo(n))ranges using the fast path