Cloud Wu:
> Lua 5.5 optimized array storage by storing the Tag after the array and
> the Value before the array. I wonder if we could further optimize
> scenarios where the entire array contains values of the same type by
> storing only a single unique Tag in the array.
I think this would be interesting, but it adds complexity for the
implementation.
Every array access would first need to check what type of array it has
to deal with slowing down the array access. Similar for storing values
in the array. Also most arrays have nil values since the array is
resized in larger steps. It would be possible to use asize for the
separation between values and nils in case of this special array type,
but this would again add complexity in the array assignment path.
Furthermore, there would be the question when to stop. I would assume
that arrays of integers with only the values 0 to 255 are quite often
used too. This could be optimized to use a byte array. What about an
array of boolean values? It could be a bit array. And not long after you
have 20 specialized types of arrays adding complexity and needing to be
maintained.
In short I do not think the implementation complexity and slowdown is
worth the 1 byte save per array entry.
If the memory is a concern there is always the C API which allows to
implement these optimized arrays with the help of userdata types which
can also be garbage collected.
Regards,
Xmilia