-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid allocations in views of views #53231
Conversation
IIUC the benchmark above is somehow "biased" julia> a = randn(100);
julia> b1 = a[100:-1:1]; b2 = view(a, 100:-1:1); # This is bad
julia> @btime sum($b1)
6.900 ns (0 allocations: 0 bytes)
-13.657826292798031
julia> @btime sum($b2)
30.282 ns (0 allocations: 0 bytes)
-13.65782629279803
julia> c1 = a[1:100]; c2 = view(a, 1:100); # This is good
julia> @btime sum($c1)
7.000 ns (0 allocations: 0 bytes)
-13.65782629279803
julia> @btime sum($c2)
7.207 ns (0 allocations: 0 bytes)
-13.65782629279803 In this sense we'd better reduce the reindex layer when possible. |
@N5N3 That is a good observation. Is that something the user can choose however at the point of creating the subarray, as they can either |
Emm, user can always handle nested |
Co-authored-by: N5N3 <2642243996@qq.com>
Note, #56760 was bisected to be caused by this PR. |
Given the significant scope of regression in TTFX, we should probably revert this for now. |
do we only want to revert the |
No, this is reproducible with 1-d as well. See my simultaneous MWE over at #56760 (comment). I think the better option would be to add yet more indirection and have |
This reverts commit 2bd4cf8.
This reverts commit 2bd4cf8. (#53231) The reason for this revert is that it caused exponential blowup of types in iterated views causing some packages to simply freeze when doing something that worked ok in 1.10. In my opinion, the perf gain from the PR is not outweighed by the "risk" of hitting this compilation blowup case. Fixes #56760. Co-authored-by: KristofferC <kristoffer.carlsson@juliacomputing.com>
This reverts commit 2bd4cf8. (#53231) The reason for this revert is that it caused exponential blowup of types in iterated views causing some packages to simply freeze when doing something that worked ok in 1.10. In my opinion, the perf gain from the PR is not outweighed by the "risk" of hitting this compilation blowup case. Fixes #56760. Co-authored-by: KristofferC <kristoffer.carlsson@juliacomputing.com> (cherry picked from commit b23f557)
Currently, views-of-views construct their re-indexed indices by slicing into the parent indices. This PR changes this to use views of the parent indices instead. This makes the operation faster and non-allocating if the
parentindices
for the original view areVector
s.Indexing into the resulting view seems equally fast in simple cases: