Skip to content
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

huge performance hit in 0.6: negative of a sparse matrix #19503

Closed
StephenVavasis opened this issue Dec 4, 2016 · 2 comments
Closed

huge performance hit in 0.6: negative of a sparse matrix #19503

StephenVavasis opened this issue Dec 4, 2016 · 2 comments
Labels
performance Must go faster potential benchmark Could make a good benchmark in BaseBenchmarks sparse Sparse arrays

Comments

@StephenVavasis
Copy link
Contributor

There appears to be a huge performance problem with taking the negative of a sparse matrix in 0.6. Observe the following timings for the code below (64-bit Windows 10 machine):

0.4.6:

julia> VERSION
v"0.4.6"

julia> @time test_minus_sparse.tms(4,10000)
  0.024588 seconds (106 allocations: 28.906 MB, 17.33% gc time)
-7.818594853651364

0.6.0-dev:

julia> VERSION
v"0.6.0-dev.1378"

julia> @time test_minus_sparse.tms(4,10000)
 10.796751 seconds (140 allocations: 28.757 MB, 0.11% gc time)
-7.818594853651364

Code:

module test_minus_sparse

function tms(ntrial,n)
    is = zeros(Int64,0)
    js = zeros(Int64,0)
    es = zeros(0)
    for i = 1 : n
        for k = max(1,i-10) : min(n, i+10)
            push!(is, i)
            push!(js, k)
            push!(es, sin(Float64(i)) * cos(Float64(k)))
        end
    end
    s = sparse(is,js,es,n,n)
    sum_e = 0.0
    for j = 1 : ntrial
        t = -s
        sum_e += t[1,1]
        s[1,1] += 1.0
    end
    sum_e
end
end
@JaredCrean2
Copy link
Contributor

I looked into this a little bit and found:

on 0.4

julia> s = sprand(100, 100, 0.1)
julia> @which -(s)
-(A::SparseMatrixCSC{Tv,Ti<:Integer}) at sparse/sparsematrix.jl:674

on 0.6

julia> s = sprand(100, 100, 0.1)
julia> @which -(s)
-(A::AbstractArray) in Base at arraymath.jl:22

which looks like it iterates over all the entries, rather than the non-zero ones. @Sacha0 has been working on the sparse matrix code recently, he might know more.

@Sacha0
Copy link
Member

Sacha0 commented Dec 4, 2016

Seems I missed reinjecting unary minus as a short child of broadcast in #17265. Time allowing I will fix this issue tomorrow. (Edit: Apologies for the delay, prioritized #19518.) Thanks for catching this!

@KristofferC KristofferC added potential benchmark Could make a good benchmark in BaseBenchmarks performance Must go faster sparse Sparse arrays labels Dec 4, 2016
lbollar added a commit to lbollar/julia that referenced this issue Dec 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster potential benchmark Could make a good benchmark in BaseBenchmarks sparse Sparse arrays
Projects
None yet
Development

No branches or pull requests

4 participants