# Allocations of @threads

**URL:** <https://discourse.julialang.org/t/allocations-of-threads/67047>\
**Category:** Performance\
**Tags:** memory-allocation\
**Created:** [August 26, 2021, 4:25pm UTC](https://discourse.julialang.org/t/allocations-of-threads/67047 "2021-08-26T16:25:52Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![ranocha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranocha/32/35588_2.png) [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Post date:** [August 28, 2021, 2:51pm UTC](https://discourse.julialang.org/t/allocations-of-threads/67047/4 "2021-08-28T14:51:10Z")

</div>

The allocations introduced by `Threads.@threads` were also one of the reasons why I started an [older discussion on the overhead of this macro](https://discourse.julialang.org/t/overhead-of-threads-threads/53964). Finally, we switched to `@batch` from [Polyester.jl](https://github.com/JuliaSIMD/Polyester.jl) (which wasn’t available back then) in [Trixi.jl](https://github.com/trixi-framework/Trixi.jl), our package for hyperbolic PDEs. The macro `@batch` includes a check whether only a single thread is used; if so, it will run the plain serial code, allowing you to see allocations in your inner functions. If multiple threads are used, which can be really helpful when developing code. If multiple threads are used, it usually creates much less allocations than `Threads.@threads`.  
However, let me warn you that `@batch` isn’t as general as `Threads.@threads`. Additionally, we ran into some interesting bugs, but Chris Elrod was really helpful and fixed all the problems very fast (as always!).

---

_[View the full topic](https://discourse.julialang.org/t/allocations-of-threads/67047)._
