# Slowdown of Distributions.jl on 0.7?

**URL:** <https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243>\
**Category:** Performance\
**Created:** [July 8, 2018, 10:12am UTC](https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243 "2018-07-08T10:12:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [July 8, 2018, 10:12am UTC](https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243/1 "2018-07-08T10:12:55Z")

</div>

I’m seeing a big slowdown in some code that uses Distributions.jl on 0.7 (built from master this morning), compared to 0.6.3. A MWE is

```julia
using Distributions

function main()
    a = zeros(100)
    y = rand(30)
    for i = 1:100
        d = Exponential(rand())
        a[i] = mean(logpdf.(d, y))
    end
end
main()

```

On 0.7 built from master today, the second run gives

```julia
julia> versioninfo()
Julia Version 0.7.0-beta.205
Commit e8dd4119b9 (2018-07-08 08:59 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, broadwell)

julia> @time include("TryIt.jl")
  **2.087699** seconds (84.38 k allocations: 4.667 MiB, 0.50% gc time)

```

While on 0.6.3, the second run gives

```julia
julia> versioninfo()
Julia Version 0.6.3
Commit d55cadc350 (2018-05-28 20:20 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)

julia> @time include("TryIt.jl")
  **0.145669** seconds (48.17 k allocations: 2.572 MiB)

julia> 

```

So, there is a tremendous slow-down. Is this the closure problem, perhaps? If so, how do I write the code properly?

I know that Distributions.jl was recently made to work on 0.7, and perhaps this is a known problem? If not, I can file an issue.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [July 8, 2018, 4:42pm UTC](https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243/2 "2018-07-08T16:42:33Z")

</div>

A post was split to a new topic: [Arpack.jl install error with MKL](https://discourse.julialang.org/t/arpack-jl-install-error-with-mkl/12254)

---

<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:** [July 8, 2018, 11:54am UTC](https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243/3 "2018-07-08T11:54:40Z")

</div>

I think you are running into a silent deprecation warning. Use `--depwarn=yes` to get

```julia
ERROR: broadcast will default to iterating over its arguments in the future. Wrap arguments of
type `x::Exponential{Float64}` with `Ref(x)` to ensure they broadcast as "scalar" elements.

```

and then fixing as

```julia
        a[i] = mean(logpdf.(Ref(d), y))

```

yields

```julia
julia> @benchmark main()
BenchmarkTools.Trial: 
  memory estimate: 34.02 KiB
  allocs estimate: 102
  --------------
  minimum time: 33.536 μs (0.00% GC)
  median time: 34.602 μs (0.00% GC)
  mean time: 43.728 μs (13.85% GC)
  maximum time: 42.665 ms (99.88% GC)
  --------------
  samples: 10000
  evals/sample: 1

julia> VERSION
v"0.7.0-beta.204"

```

vs

```julia
julia> @benchmark main()
BenchmarkTools.Trial: 
  memory estimate: 34.02 KiB
  allocs estimate: 102
  --------------
  minimum time: 52.695 μs (0.00% GC)
  median time: 53.716 μs (0.00% GC)
  mean time: 60.395 μs (1.65% GC)
  maximum time: 837.051 μs (87.87% GC)
  --------------
  samples: 10000
  evals/sample: 1

julia> VERSION
v"0.6.3"

```

which is a reasonable improvement, demoing v0.7 awesomeness.

---

<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:** [July 8, 2018, 11:57am UTC](https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243/4 "2018-07-08T11:57:54Z")

</div>

BTW, I wonder why these deprecation warnings are not showing by default.

---

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [July 8, 2018, 12:42pm UTC](https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243/5 "2018-07-08T12:42:25Z")

</div>

Great! Thanks! I agree that 0.7 is awesome, and I’m really happy to see that this only slowdown I’ve encountered has a simple solution.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [July 9, 2018, 3:08am UTC](https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243/6 "2018-07-09T03:08:06Z")

</div>

This is a good question. I wonder if it’s a big in the deprecation system. Was this deprecation perhaps shown earlier in the same session?

---

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [July 9, 2018, 5:16am UTC](https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243/7 "2018-07-09T05:16:08Z")

</div>

I believe that I did see the warning at the beginning of the process, but not while I was trying to figure out what to do.

---

<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:** [July 9, 2018, 5:30am UTC](https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243/8 "2018-07-09T05:30:35Z")

</div>

I can confirm that it is shown, I may have missed it because of other warnings previously.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [July 9, 2018, 2:30pm UTC](https://discourse.julialang.org/t/slowdown-of-distributions-jl-on-0-7/12243/9 "2018-07-09T14:30:52Z")

</div>

Ok, then this is all working as it should.
