As a Roblox developer, it is currently still too hard to do performant bulk manipulation of tables.
If Roblox is able to address this issue, it would improve my development experience because it would allow for complex table manipulation to be done performantly.
The WebAssembly spec has examples of these operations using similar terminology to Roblox. The only difference here is that WebAssembly doesn’t automatically resize tables for you, but all of a program’s use cases for these operations still exist in lua and on Roblox in many places.
https://webassembly.github.io/spec/core/exec/instructions.html#xref-syntax-instructions-syntax-instr-table-mathsf-table-grow-x
Being able to resize (grow/shrink) tables & fill values into them would complete Roblox’s set of table manipulation functions. Roblox has table.create
(functionally equivalent to table.init
on wasm spec), and table.move
(functionally equivalent to table.copy
on wasm spec), however, Roblox does not have a way to fill into or resize the array parts of tables, which, are both operations that are very important in many programs.
Additionally, its important for me to point out why these operations are needed in place of letting Roblox/luau handle it. Tl;dr, for the same and similar reasons that table.create
& table.clear
are needed and were implemented, a way to resize and fill tables is also needed.
(This explanation is extremely long and not fully relevant to the request)
Firstly, iirc the way that Roblox resizes tables is by allocating to the next power of two when needed, and, this is okay in most cases, but for the same reason that table.create
greatly assists with the performance and memory cost of tables when used correctly, the ability to resize tables would too.
Say you have a large set of objects you’re tracking. Maybe you’re doing inverse kinematics, or stepping entities, etc.
You may have 10 objects you’re tracking in the world. But now let’s say you have a list of 1000 objects you created, maybe a player just joined and you’re loading their base that has a lot of objects in it. You could insert them one by one and face the costs of the extra allocations, or you could allocate a new table for 1010 objects, temporarily using extra memory and providing more work for the garbage collector. The ability to resize a table in this case would perfectly solve this issue, just like table.create
does.
Additionally, in the case that those 1000 objects are removed, for example, let’s say a player has a base with many objects you are tracking, and they leave, and you want to delete those tracked objects, now you are stuck in the same dilemma that resizing tables would resolve.
As for table filling, table.clear functions similarly to a fill. For example, table.fill(tab, 1, #tab, nil)
would function almost identically (if it were a thing). But, there’s no way to specify the value or range to be filled in that case, and while nil
may be lua’s version of nothing, that might not be the version of nothing you need. Or, perhaps you just know you need to fill a large range with the same value, for example, a compression algorithm might take advantage of table filling in Roblox.
A fill operation in lua, which knows how many values its updating can also limit any allocations that would need to be applied to do that fill. For example, table.fill({}, 1, 1000, 0)
could function very similarly to table.create(1000, 0)
.