5/21/2025 at 4:52:42 PM
> Components are stored in contiguous arrays in a SoA (Structure of Arrays) manner, which allows for fast iteration and processingDoes this actually matter in Lua? Aren’t all array elements going to be pointers to heap allocated objects anyways?
The point of SoA is your likely to be accessed values are adjacent in memory, but if you’re chasing a pointer to get that value then you’re not getting anything out of it.
by cmovq
5/21/2025 at 9:40:10 PM
Yes, organizing components as SoA can provide a significant performance boost in Lua, especially with LuaJIT. Both iteration and element access become faster, and it also reduces memory allocations and GC pressure when creating entities. And yes, Lua tables can be contiguous in memory if you use them carefully.by blackmat
5/22/2025 at 5:42:52 AM
Do you have any published benchmarks?by dicytea
5/22/2025 at 8:21:00 AM
Comparative benchmarks are a big task on their own, and usually the author's library wins in them. I have internal benchmarks in the repository, but they are not designed for comparison or for evaluation by outsiders. Maybe I'll get to that someday.As for the SoA approach, here you can find a small and exaggerated example: https://luajit.org/ext_ffi.html
by blackmat
5/21/2025 at 5:08:50 PM
Lua uses tagged unions so that primitives are stored inline within a table. Some time ago I benchmarked this and the perf gains from SOA were significant. Besides, even if you had to chase pointers, SOA still means you can reduce the number of allocations.by PhilipRoman