Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Isn't SoA basically always more performant though? You're either traversing individual "columns" and leveraging cache locality, or you're not and then you can traverse multiple columns in parallel to rebuild the structs on the fly.

I could only see this degrade or be suboptimal if you have a very small struct that still all in-cache (like an array of 3d coordinates or something)



If you’re always accessing all the members then no. SoA shines when you want to access a different set of a few members of a struct in different contexts. Then there’s also the option of building temporary arrays of just the data you need then spinning through it which can be faster for some things. For example rendering pipelines. Even more so if you cache the results and can use them next frame due to temporal locality. There’s no silver bullet you’ve got to sit down and look at your access patterns and profile.


SOA is optimal only if you are iterating sequentially over many elements on a subset of the columns.

Really the right layout is access dependent.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: