Compact Representations for Arrays in Lua [pdf]
9 comments
·June 18, 2025kzrdude
It was published in September 2024, so it's relatively recent.
Jyaif
Jesus christ, 40% waste in arrays that can be solved by using `__attribute__((packed))`.
Irresponsible of them of not advertising this as an option in luaconf.h
sfpotter
Here's the rest of that paragraph for you:
"However, this attribute is a gcc extension not present in ISO C. Moreover, even in gcc it is not guaranteed to work [3]. As portability is a hallmark of Lua, this almost magical solution is a no-go."
Jyaif
It works in gcc and LLVM, on both arm and x86, so I'd say conservatively that 90% of their users are covered.
kragen
You have no idea what 90% of their users are using. A lot of them aren't using LLVM or GCC. I'm pretty sure Roblox and WoW, for example, aren't normally compiled with LLVM or GCC. Whether those two games account for 99% of Lua's users or 0.001% depends on how you count, but no matter how you count, you have no idea.
mananaysiempre
Embedders of Lua are not equidistributed across platforms with the general population of programmers or with user-exposed general-purpose computers. Not even close. One of the selling points of Lua is how easy it is to run on a toaster or potato, so disproportionately many ports of Lua are in fact running on toasters and potatoes.
This optimization might land in the next Lua release. More specifically, the "Reflected Arrays" version (Figure 6).
https://github.com/lua/lua/blob/f71156744851701b5d5fabdda506...