-
-
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
Sparse matrix: fix fast implementation of findnext and findprev for cartesian coordinates #32007
Conversation
…#31354)" This seems to duplicate work from JuliaLang#23317 and it causes performance degradation in the cases that one was designed for. See JuliaLang#31354 (comment) This reverts commit e0bef65.
Pinging @mbauman @andreasnoack for review. |
We need to decide what to do for 1.2 here. Either leave things as is, revert #31354, or merge this and backport to the 1.2 branch. |
Does this maintain the performance improvements for the common case described in #31354? If so, let's merge this, and also add test cases to prevent regression. My preference is then to backport. |
Yes, it maintains the same behaviour of |
Ah, ok, this is indeed much simpler. Just to wrap my own head around what happened here:
julia> using Revise, SparseArrays, BenchmarkTools
julia> Revise.track(SparseArrays)
julia> A = spzeros(10000,10000);
julia> A[end,end]= 1
1
julia> @benchmark findnext(isequal(0), $A, CartesianIndex(1,1))
BenchmarkTools.Trial:
memory estimate: 240 bytes
allocs estimate: 5
--------------
minimum time: 700.908 ns (0.00% GC)
median time: 752.756 ns (0.00% GC)
mean time: 812.077 ns (9.16% GC)
maximum time: 448.030 μs (99.81% GC)
--------------
samples: 10000
evals/sample: 119
julia> @benchmark findnext(!isequal(0), $A, CartesianIndex(1,1))
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 27.390 ns (0.00% GC)
median time: 29.360 ns (0.00% GC)
mean time: 28.993 ns (0.00% GC)
maximum time: 47.038 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 995
shell> git merge --no-commit pr/32007
Automatic merge went well; stopped before committing as requested
julia> @benchmark findnext(isequal(0), $A, CartesianIndex(1,1))
BenchmarkTools.Trial:
memory estimate: 240 bytes
allocs estimate: 5
--------------
minimum time: 683.640 ns (0.00% GC)
median time: 736.847 ns (0.00% GC)
mean time: 791.763 ns (8.20% GC)
maximum time: 376.179 μs (99.77% GC)
--------------
samples: 10000
evals/sample: 150
julia> @benchmark findnext(!isequal(0), $A, CartesianIndex(1,1))
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 6.755 μs (0.00% GC)
median time: 6.774 μs (0.00% GC)
mean time: 6.955 μs (0.00% GC)
maximum time: 13.100 μs (0.00% GC)
--------------
samples: 10000
evals/sample: 5 |
This could use extra test cases to cover what broke. |
I think it was only performance? |
@mbauman yes, your summary sums it up. As for your spot benchmarks -- I identified the reason for the slower performance and am about to add a fix for them to this branch. |
Thanks to @mbauman for spotting this issue in JuliaLang#32007 (comment).
6a0d49b
to
9c3a15b
Compare
@JeffBezanson and @KristofferC , yes it was only performance. |
…artesian coordinates (#32007) Revert "sparse findnext findprev hash performance improved (#31354)" This seems to duplicate work from #23317 and it causes performance degradation in the cases that one was designed for. See #31354 (comment) This reverts commit e0bef65. Thanks to @mbauman for spotting this issue in #32007 (comment). (cherry picked from commit ec797ef)
This wasn't backported to RC2 because it still had the triage label on. I assume that we just go with this PR though. |
…artesian coordinates (#32007) Revert "sparse findnext findprev hash performance improved (#31354)" This seems to duplicate work from #23317 and it causes performance degradation in the cases that one was designed for. See JuliaLang/julia#31354 (comment) This reverts commit 8623d9a. Thanks to @mbauman for spotting this issue in JuliaLang/julia#32007 (comment).
#23317 introduced special cases for
findnext
in cases of sparse vectors/matrices. The case of matrices was inadvertently broken whenCartesianIndex
was introduced. This pull request fixes that.In addition, a recent pull request (#31354) identified a need for
findprev(f, m)
to have a sparse implementation not only for the casef == !iszero
, but also for anyf
that hasf(zero(eltype(m)))
equal tofalse
. In particular, thehash
function is a heavy user offindprev(!isequal(x), m)
for different values ofx
, includingx == 0
. This is part of this branch, as well.I feel incredibly bad about submitting this pull request here as one of its commits is a revert of #31354 . These are my reasons for taking that step:
eltype(m) == BigInt
(or any othereltype
that exists on the heap), the test forf(zero(...))
does an allocation which quickly becomes a major bottleneck.I did make a point of including the new test cases from the other pull request. For example, that ensures that these functions work with
as their argument.