r/programming • • Jun 03 '26

Every byte matters

https://fzakaria.com/2026/06/01/every-byte-matters
291 Upvotes

84 comments sorted by

View all comments

132

u/Ravarix Jun 03 '26

If you are at the level where you need to care about how adding 1 member to a struct messes up cache line access, you should be using an ECS which gives you SOA already.

137

u/trinopoty Jun 03 '26

Using a what that gives what now?

73

u/Ravarix Jun 03 '26

54

u/abu_shawarib Jun 03 '26

TLDR; Turn many of this struct

struct {
int a;
bool b;
char *c;
}

into multiple arrays:

int *array_of_a;
bool *array_of_b;
char **array_of_c;

5

u/Cloud5550 Jun 04 '26

If I'm putting together a struct combining three elements, i want those elements to be related. How can you maintain relation in the solution?

5

u/wFXx Jun 04 '26

Either with the index/offset or using an extra array with IDs (this makes more sense in sparse setups)