I read binary data into a sparse matrix. Basically I populate a row and data vector with append! and put them into a sparse matrix using SparseMatrixCSC. It was very fast on 0.6, but is 200x+ slower on 0.7. I haven’t changed the code, apart from fixing warnings which was related to allocating arrays. This is what I get:
Less allocation but 236 times slower. Profiling 0.6 shows nothing of interest. However, for 0.7 I get this (snippet):
56992 ./array.jl:873; append!
1 ./abstractarray.jl:768; copyto!(::Array{Int32,1}, :...
5 ./abstractarray.jl:770; copyto!(::Array{Int32,1}, :...
5 ./deprecated.jl:1615; Type
5 ./abstractarray.jl:83; axes
5 ./tuple.jl:162; map
5 ./range.jl:226; Type
5 ./range.jl:217; Type
5 ./promotion.jl:436; max
56973 ./abstractarray.jl:771; copyto!(::Array{Int32,1}, :...
2 ./int.jl:52; -
720 ./operators.jl:950; in
720 ./promotion.jl:425; ==
47438 ./operators.jl:953; in
8813 ./operators.jl:954; in
I’m not really sure what happens inside append!, but the code seem to be stuck in append! and copyto! a lot. Is this something known I’m not aware of? Something I can do about it or wait for a fix?
Some of the sparse functionality was moved to a standard library package SparseArrays in v0.7, so if you don’t have using SparseArrays, you will get deprecation warnings in v0.7 which will make your code much much slower.
To fix that, just add using SparseArrays to your code before you do any sparse operations in Julia v0.7.
In 1.0 and above, you’ll just get an error message without using SparseArrays rather than a deprecation warning which works but is slow.
Does that improve things?
Otherwise, it’s hard to say without seeing your code.
Forgot to mention I fixed that warning too, meaning I have using SparseArrays in my module.
I though so, however for this package I can’t disclose the source. I was mostly wondering if there are known issues with append! and/or sparse matrices (I’m not doing any transposes, just populating a sparse matrix).
Maybe worth mentioning is that the issue persists on the current nightly (2018-07-14).
I think this fixed the non-MWE code as well. Right now I just redefined the corresponding functions with Base.copyto!... in the REPL. Results from original code below, reading a 340002 x 340002 sparse matrix.
Without fix:
@time main() # second run
112.393334 seconds (4.35 M allocations: 126.643 MiB, 0.07% gc time)
With fix:
@time main() # second run
0.718545 seconds (4.35 M allocations: 126.643 MiB, 7.83% gc time)
With append2! from above:
@time main() # second run
0.815360 seconds (4.36 M allocations: 126.860 MiB, 7.74% gc time)