# Struct of Arrays (SoA) vs Array of Structs (AoS)

**URL:** <https://discourse.julialang.org/t/struct-of-arrays-soa-vs-array-of-structs-aos/30015>\
**Category:** Performance\
**Tags:** performance\
**Created:** [October 17, 2019, 8:34am UTC](https://discourse.julialang.org/t/struct-of-arrays-soa-vs-array-of-structs-aos/30015 "2019-10-17T08:34:57Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [October 17, 2019, 11:35am UTC](https://discourse.julialang.org/t/struct-of-arrays-soa-vs-array-of-structs-aos/30015/4 "2019-10-17T11:35:50Z")

</div>

Struct of Arrays are great when you want to SIMD across loop iterations.  
That is, if your code is written as a loop that does some calculations with structs, the Struct of Arrays memory layout allows the compiler to calculate multiple iterations of the loop at a time. This is because it is straight forward to turn each access to a number into a load of an entire SIMD vector of them, etc for each subsequent operation.

This vectorization requires `@inbounds` to eliminate branches. It may require `@simd for` or even `@simd ivdep for` to vectorize.  
You can check if it has been vectorized with `@code_llvm`.

---

_[View the full topic](https://discourse.julialang.org/t/struct-of-arrays-soa-vs-array-of-structs-aos/30015)._
