lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I agree with this approach, as long as you keep the paradigm of the split between an array part and an hashed part. However I'm not even convinced that this is the best way to handle tables, the benefit it gives for a supposed optimization of speed or access time or memory allocation/GC is quite doubtful. And it has brought various bugs or instabilities or incompatible behaviors.

A safe implementation should use invariants, but Lua does not fix them reliably. I'm now convinced that it is a problem to create a good ecosystem of reusable libraries. And the obvious symptom of this is that most projects we eloped in Lua are stocked to a si gle version and refuse to upgrade. In fine, o'er versions are left unmaintained, security holes are found but not fixed in versions that application supports, or this effectively cause many forks to be developed or maintained separately. This is bad for the long term evolutions of Lua. The only safe way is to remove the unsoefied behavior of tables. 

Le sam. 25 juil. 2020 à 13:28, Jasper Klein <jasper@klein.re> a écrit :
Op zaterdag 25 juli 2020 08:29:47 CEST schreef Philippe Verdy:
> and all the rest is populated by
> assignments, the array part is not evolving, there's no strategy to move
> items from the hash part to the array part.

A while back I did some investigation about forcing the size for the array part and the hash part of a table.
In Lua 5.3.5, when the table grows, it may trigger a rehash.
When rehashing, an integer key may be moved to the array part if the sequence is contiguous.
This happens in ltable.c in the functions 'luaH_newkey', 'rehash', 'luaH_resize' and 'reinsert'.

-- Jasper