6/3/2026 at 1:52:55 PM
The article shows nicely how "every byte matters" is false. First, it starts off by talking about the cost of a new field, when the actual topic is array-of-structs vs. struct-of-arrays. Then, this:> How much of an impact can this have? > Reading is:alive (1 byte) Across 1M Monsters
You aren't reading one byte here, you are reading 1M bytes! Of course, optimizing the access to 1M bytes is something to consider. Optimizing the access to one byte isn't.
The article is definitely worth reading IMHO, but it really needs a better headline!
by moring
6/3/2026 at 1:56:42 PM
Even more so, it shows that SoA data structure means you can add fields to your 1M monsters with little impact.by jayd16
6/3/2026 at 3:57:42 PM
This is valid for sequential scanning of the data. The CPU will fill whole cache lines at once with the arrays that do get used and the algorithm touches all the field instances in the array.Now think about random access to single struct instances instead: the CPU loads a cache line worth of data for each field and uses only one element out of the whole cache line. This is much worse than a compact structure representation of the same data.
SoA is not universally better.
by gmueckl
6/3/2026 at 4:04:41 PM
No it's not always better and I didn't mean to imply it was. I was simply saying that the article argues against its title.In both cases you want to think about locality of the next read and structure the data accordingly.
by jayd16
6/3/2026 at 2:36:04 PM
> you can add fields to your 1M monsters with little impact.Great for this access pattern, but I wouldn't make a general statement like that. This is the same thing as row-oriented vs column-oriented databases, OLTP vs OLAP. SoA is weak if you are adding/removing monsters more often than accessing a single "hot" field.
by notatyrannosaur
6/3/2026 at 3:17:35 PM
> SoA is weak if you are adding/removing monsters more often than accessing a single "hot" field.Why is that? Genuinely curious. Does "weak" mean that it performs worse than AoS, or that the gains aren't as significant versus AoS?
by Altern4tiveAcc
6/3/2026 at 4:00:39 PM
It's because removing a monster with 20 fields from an SoA structure means resizing 20 arrays. Removing the same monster from an AoS array involves resizing a single array, which you're going to process in a very cache friendly way.by tsimionescu
6/3/2026 at 5:45:26 PM
I'm not sure why anybody would at the same time be implementing SoA AND resizing 20 arrays for a single delete, those things seem to be on either ends of the "I care about performance" spectrum.by vouwfietsman
6/3/2026 at 4:22:15 PM
Assuming ordering isn't a concern, can't you just have a field called "removed" and skip those when iterating?Or swap it with the last monster, and keeping an index for the last monster alive.
by Altern4tiveAcc
6/3/2026 at 4:42:14 PM
Then you have to read the "removed" field on every field read on every operation.SoA is only useful when you don't read multiple fields for most operations.
by marcosdumay
6/3/2026 at 3:25:34 PM
Presumably they're referring to resizing the arrays.by jayd16
6/3/2026 at 3:51:55 PM
Array resizing is avoidable with an embedded free list if ordering is of no concern.by gmueckl
6/3/2026 at 3:20:25 PM
[dead]by keynha
6/3/2026 at 2:14:58 PM
Yes. I think one of the big advantages of SoA is that you only pay for the fields you're currently using. If you need a field somewhere, you can add it and only pay the cost of iterating it where you need it.by celrod
6/3/2026 at 2:59:59 PM
Every Struct Mattersby bronlund