4 ms·
I feel like "struct of arrays" style coding has really taken off in the past decade, and seems to be the best way to maximize memory operations these days. Its
by dragontamer 5y ago
I feel like "struct of arrays" style coding has really taken off in the past decade, and seems to be the best way to maximize memory operations these days.
Its not so much that "structure packing" is dead, as much as a wide variety of techniques have been developed above-and-beyond just simply structure packing. There's many ways to skin a cat these days, and packing your structures more intelligently is just one possible data optimization.
- kolbusa 5y agoIt really depends on the domain. HPC is more frequently SOA (think CSR sparse matrices), while AOS may make more sense in other cases.
- monocasa 5y agoWasn't that one of the cool things about the language Jai? Struct definitions could be cleanly inverted between AoS and SoA at use time?
- pclmulqdq 5y ago"Struct of arrays" becoming popular may also have something to do with few people understanding structure packing. AOS has much better performance if you pack your structs well than if you pack them naively.
- layer8 5y agoThat entirely depends on the access patterns. SOA makes sense when you don’t often access the different fields of the same object (array index) at the same time. If you do, on the other hand, then AOS is more efficient.
- TillE 5y agoRight. There's a little too much cargo-culting in the "struct of arrays" pattern, you really want to understand why it works or doesn't. If you have some giant bloated struct and you only care about one or two fields at a time, that's one thing. But if you have a well-aligned, correctly packed struct and you're processing all its data, it's total nonsense to break that up.
- layer8 5y agoIt’s similar to row vs. column oriented databases.
- dragontamer 5y agoI certainly think SOA has been cargo-culted to all hell and back. But empirically speaking, it seems like SOA / AOS is the easiest "beginner topic" to get high performance-programmers thinking about memory-layout issues. Maybe in the 90s or 00s, it was more popular to think about struct layouts, alignment issues and the like. But today, SOA is popular because RAM has gotten less... random... and more sequential. I think its the changing nature of 90s era computers (RAM behaving more random-accessy) vs the nature of 10s era computers (RAM behaving more sequential-accessy) -------- Its not like the 90s techniques don't work anymore. But the 10s technique of "structure of arrays" and then iterating for-loops over your data works better with prefetchers, multiple-cache hierarchies, and other tidbits that have made RAM more sequential than ever before. Hopefully programmers continue to study the techniques and understand what is going on under-the-hood, instead of cargo-culting the pattern. Alas, we all know that cargo-culting works in the short term and is easier to do than actually learning the underlying machine!
- edflsafoiewq 5y agoIn modern dynamic languages, it usually easy to have an array of floats or ints, but an array of structs may not even really exist. Also of course AoS has fixed fields, while SoA has dynamic fields.