# Does @asyc or Threads.@spawn affect performance

**URL:** <https://discourse.julialang.org/t/does-asyc-or-threads-spawn-affect-performance/39118>\
**Category:** Julia at Scale\
**Created:** [May 8, 2020, 3:47pm UTC](https://discourse.julialang.org/t/does-asyc-or-threads-spawn-affect-performance/39118 "2020-05-08T15:47:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuel\_okon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samuel_okon/32/10285_2.png) [@samuel\_okon](https://discourse.julialang.org/u/samuel_okon)\
**Post date:** [May 8, 2020, 3:47pm UTC](https://discourse.julialang.org/t/does-asyc-or-threads-spawn-affect-performance/39118/1 "2020-05-08T15:47:32Z")

</div>

To my understanding `@async` creates a closure which may box a variable. And the docs say boxing affects performance. Or is there something am getting wrong. ? (Am aware of the interpolation operator in julia \>= 1.4).

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [May 8, 2020, 7:54pm UTC](https://discourse.julialang.org/t/does-asyc-or-threads-spawn-affect-performance/39118/2 "2020-05-08T19:54:26Z")

</div>

Yes `@async` or `@spawn` has overhead. However if you have multiple tasks that can be done in parallel rather than serially, then that overhead is worth it.

If you are doing:

```julia
Threads.@spawn a = b + c
Threads.@spawn d = e + f
Threads.@spawn g = h + i

```

You are not going to see any performance improvement since the work required to run those in parallel will outweigh the time needed to perform the addition. You probably don’t want to try to run tasks that will finish in less than a second in parallel.

The only way to truly know if you will get a performance improvement is to first write it in serial, debug it, benchmark it, then parallelize it, make sure you get the same result, and benchmark it.

---

<div class="post-metadata">

**Author:** ![samuel\_okon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samuel_okon/32/10285_2.png) [@samuel\_okon](https://discourse.julialang.org/u/samuel_okon)\
**Post date:** [May 8, 2020, 8:00pm UTC](https://discourse.julialang.org/t/does-asyc-or-threads-spawn-affect-performance/39118/3 "2020-05-08T20:00:00Z")

</div>

Thanks
