# Huge performance hit in 0.6.0 for sparse matrix concatenation

**URL:** <https://discourse.julialang.org/t/huge-performance-hit-in-0-6-0-for-sparse-matrix-concatenation/5419>\
**Category:** General Usage\
**Created:** [August 17, 2017, 3:04am UTC](https://discourse.julialang.org/t/huge-performance-hit-in-0-6-0-for-sparse-matrix-concatenation/5419 "2017-08-17T03:04:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)\
**Post date:** [August 17, 2017, 3:04am UTC](https://discourse.julialang.org/t/huge-performance-hit-in-0-6-0-for-sparse-matrix-concatenation/5419/1 "2017-08-17T03:04:10Z")

</div>

I finally ported my code from 0.5.2 to 0.6.0 and discovered that a test run that took 8h35min in 0.5.2 now takes 15hr in 0.6.0. I have traced the performance problem to the following statement, which takes over 7 times longer in 0.6.0 than in 0.5.2:

```julia
    bobhess = [hessxx hessxs hessxt
               hessxs' hessss hessst
               hessxt' hessst' hesstt]

```

in which all the entries `hessxx`, …, `hesstt` are sparse matrices or vectors. Is this a known issue? (If not, I’ll open one.) Is there a workaround?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 17, 2017, 5:32am UTC](https://discourse.julialang.org/t/huge-performance-hit-in-0-6-0-for-sparse-matrix-concatenation/5419/2 "2017-08-17T05:32:52Z")

</div>

A minimal working example would be helpful.

---

<div class="post-metadata">

**Author:** ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)\
**Post date:** [August 17, 2017, 2:33pm UTC](https://discourse.julialang.org/t/huge-performance-hit-in-0-6-0-for-sparse-matrix-concatenation/5419/3 "2017-08-17T14:33:45Z")

</div>

Based on the response to my posting, I conclude that the issue raised is not previously known, so I have opened an issue with a test example:

[https://github.com/JuliaLang/julia/issues/23296](https://github.com/JuliaLang/julia/issues/23296)

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 17, 2017, 6:01pm UTC](https://discourse.julialang.org/t/huge-performance-hit-in-0-6-0-for-sparse-matrix-concatenation/5419/4 "2017-08-17T18:01:47Z")

</div>

We **really really** need `PkgBenchmark.jl` or something similar working smoothly to make sure that all our efforts to optimize code as package writers aren’t thrown away in future releases of the language. I’ve experienced slow downs on my packages as well from Julia v0.5 to Julia v0.6, but couldn’t nail down the sources given my time constraints.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 17, 2017, 7:14pm UTC](https://discourse.julialang.org/t/huge-performance-hit-in-0-6-0-for-sparse-matrix-concatenation/5419/5 "2017-08-17T19:14:09Z")

</div>

> [@juliohm](#):
>
> We really really need PkgBenchmark.jl or something similar working smoothly

PkgBenchmark just has a few convenience function over BenchmarkTools. Defining a benchmark suite and running it on two Julia releases and comparing the results is super easy just using BenchmarkTools.

As to, PkgBenchmark, a lot of stuff has happened on master. Feel free to try it out.

---

<div class="post-metadata">

**Author:** ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)\
**Post date:** [August 17, 2017, 10:35pm UTC](https://discourse.julialang.org/t/huge-performance-hit-in-0-6-0-for-sparse-matrix-concatenation/5419/6 "2017-08-17T22:35:36Z")

</div>

Good news-- the cause of my performance hit was identified (refer to the Julia-issue link above), and a workaround was proposed by Fredrik Ekre, namely, avoid concatenating `SparseMatrixCSC` and `SparseVector`. (Change the `SparseVector` to a `SparseMatrixCSC` first). My code ran for 8hr35 in 0.5.2, 15hr in 0.6.0 before I implemented the workaround, and now 5hr48 in 0.6.0 after I implemented the workaround. So overall, a noticeable performance boost from upgrading to 0.6.0.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 18, 2017, 6:57am UTC](https://discourse.julialang.org/t/huge-performance-hit-in-0-6-0-for-sparse-matrix-concatenation/5419/7 "2017-08-18T06:57:53Z")

</div>

There is also a PR [https://github.com/JuliaLang/julia/pull/23297](https://github.com/JuliaLang/julia/pull/23297) that fixes the problem that will likely be backported to 0.6.1.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 19, 2017, 3:58pm UTC](https://discourse.julialang.org/t/huge-performance-hit-in-0-6-0-for-sparse-matrix-concatenation/5419/8 "2017-08-19T15:58:52Z")

</div>

@kristoffer.carlsson thank you for your work in PkgBenchmark.jl, I will give it a second try when I find the time. Is there a new version tagged already with the fixes?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 19, 2017, 7:14pm UTC](https://discourse.julialang.org/t/huge-performance-hit-in-0-6-0-for-sparse-matrix-concatenation/5419/9 "2017-08-19T19:14:55Z")

</div>

No, because I don’t think it has gotten enough testing to be tagged yet.
