# Not seeing speed-up with Dagger.jl. Am I doing something wrong?

**URL:** <https://discourse.julialang.org/t/not-seeing-speed-up-with-dagger-jl-am-i-doing-something-wrong/107440>\
**Category:** Julia at Scale\
**Created:** [December 11, 2023, 1:46pm UTC](https://discourse.julialang.org/t/not-seeing-speed-up-with-dagger-jl-am-i-doing-something-wrong/107440 "2023-12-11T13:46:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdas123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bdas123/32/32142_2.png) [@bdas123](https://discourse.julialang.org/u/bdas123)\
**Post date:** [December 11, 2023, 1:46pm UTC](https://discourse.julialang.org/t/not-seeing-speed-up-with-dagger-jl-am-i-doing-something-wrong/107440/1 "2023-12-11T13:46:30Z")

</div>

1. I am setting 8 CPU cores using the following code:

```julia
using IJulia
installkernel("Julia (8 threads)", env=Dict("JULIA_NUM_THREADS"=>"8"))
Threads.nthreads()

```

1. I change the kernel environment of the Jupyter Notebook to the 8 CPU core environment.

2. Run the non-Dagger command

```julia
e = zeros(173,290)
f = ones(290)

function a!(b,c,d)
    for j in 1:290
        e[t, j] = f[j]
        f[j] = e[t, j]
    end
end

@time begin

for t in 1:173
        
        a!(t)
end
end

```

The result is

```julia
  0.021634 seconds (100.34 k allocations: 1.531 MiB)

```

However, when I run the Dagger.jl command:

```julia
e = zeros(173,290)
f = ones(290)

function a!(t)
    for j in 1:290
        e[t, j] = f[j]
        f[j] = e[t, j]
    end
end

@time begin

@sync for t in 1:173
        
        Dagger.@spawn a!(t)
end
end

```

The result is:

```julia
  0.620212 seconds (283.25 k allocations: 11.632 MiB, 2.90% compilation time)

```

Am I doing something wrong? I am not seeing a speed-up from using Dagger

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 11, 2023, 2:17pm UTC](https://discourse.julialang.org/t/not-seeing-speed-up-with-dagger-jl-am-i-doing-something-wrong/107440/2 "2023-12-11T14:17:18Z")

</div>

Your code takes 0.02 seconds to run in serial, it seems very unlikely that you would amortize the overhead of distributed computing over such a trivial task?

---

<div class="post-metadata">

**Author:** ![bdas123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bdas123/32/32142_2.png) [@bdas123](https://discourse.julialang.org/u/bdas123)\
**Post date:** [December 11, 2023, 2:21pm UTC](https://discourse.julialang.org/t/not-seeing-speed-up-with-dagger-jl-am-i-doing-something-wrong/107440/3 "2023-12-11T14:21:43Z")

</div>

This is a smaller version of a much larger problem. But yes you are right, maybe I should use the parameters of the larger problem to see if distribution is helpful.

---

<div class="post-metadata">

**Author:** ![bdas123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bdas123/32/32142_2.png) [@bdas123](https://discourse.julialang.org/u/bdas123)\
**Post date:** [December 11, 2023, 2:45pm UTC](https://discourse.julialang.org/t/not-seeing-speed-up-with-dagger-jl-am-i-doing-something-wrong/107440/4 "2023-12-11T14:45:00Z")

</div>

I guess my question is more along the lines of, did I write the Dagger.jl code properly

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [December 11, 2023, 6:42pm UTC](https://discourse.julialang.org/t/not-seeing-speed-up-with-dagger-jl-am-i-doing-something-wrong/107440/5 "2023-12-11T18:42:57Z")

</div>

Dagger has reasonably high overhead right now, but even if I bring that down significantly (which I am working on), your non-Dagger code can very trivially be optimized by Julia’s compiler across calls to `a!`, whereas Dagger cannot (yet) do something like this. So it’ll be very hard for Dagger to be competitive, and I wouldn’t expect that at this small scale. Maybe try `@spawn`ing a larger set of `a!` calls as one Dagger task, to amortize overhead and let Julia’s compiler work better with Dagger?

---

<div class="post-metadata">

**Author:** ![bdas123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bdas123/32/32142_2.png) [@bdas123](https://discourse.julialang.org/u/bdas123)\
**Post date:** [December 11, 2023, 10:48pm UTC](https://discourse.julialang.org/t/not-seeing-speed-up-with-dagger-jl-am-i-doing-something-wrong/107440/6 "2023-12-11T22:48:07Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 12, 2023, 9:12am UTC](https://discourse.julialang.org/t/not-seeing-speed-up-with-dagger-jl-am-i-doing-something-wrong/107440/7 "2023-12-12T09:12:50Z")

</div>

If I may make a general comment - and I hope not to speak out of turn - from all your questions in the last days it appears that you are fairly new to Julia and are trying to jump right into the deep end.

Julia’s performance model can at times be subtle (cf. the length of the [Performance Tips · The Julia Language](https://docs.julialang.org/en/v1/manual/performance-tips/) at this point) so new users can often find remarkable speedups by focusing on implementing all performance tips while focusing on single threaded execution speed. Multithreading and distributed computing adds another layer of complexity which often isn’t helpful to get into before you are sure you’ve squeezed every bit of performance out of the basic non-parallel version of your code.

---

<div class="post-metadata">

**Author:** ![bdas123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bdas123/32/32142_2.png) [@bdas123](https://discourse.julialang.org/u/bdas123)\
**Post date:** [December 12, 2023, 9:43am UTC](https://discourse.julialang.org/t/not-seeing-speed-up-with-dagger-jl-am-i-doing-something-wrong/107440/8 "2023-12-12T09:43:44Z")

</div>

No worries, I appreciate your honesty with me. And yes, compared to the people on this forum, I am fairly new to the language.

Thanks for the link, I’ll check it out.

---

<div class="post-metadata">

**Author:** ![bdas123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bdas123/32/32142_2.png) [@bdas123](https://discourse.julialang.org/u/bdas123)\
**Post date:** [December 14, 2023, 8:16am UTC](https://discourse.julialang.org/t/not-seeing-speed-up-with-dagger-jl-am-i-doing-something-wrong/107440/9 "2023-12-14T08:16:07Z")

</div>

I’d like to thank you for sharing the Performance Tips link.

I was able to speed up performance by 2x simply be defining certain variables as “const”.
