I found out that in luau table has 2 part, one for array, one for hash part
There a quirk with the array is that nil value doesn’t automatically mark that slot as “nil” or never exist, so iterator like next, generalized will go through it, slowing it down
I.e { 1, 2, 3, 4, 5, nil, nil, nil, nil, nil }, This array have the size of 10, next and generalized will iterate through this till the end of the array size, whereas ipairs only iterate when it hit a nil, but ipairs fail when this happen { 1, 2, 3, nil, 5, 6 } which is intended and I dont think I have much case that I will come across this problem.
The thing is that, if an array dynamically grows and then reuse again but in a less populating environment, doesn’t that make iterating using next and generalized slower? So I try to figure out to resize it, I could either do table.move(t, 1, #t, 1, table.create(#t)) which seems to be the fastest to resize it or do t[""] = nil which forces it to resize to 2^n that is equal or larger than #t and faster than doing the previous but still leaves trailing nil. Also I found that next is the fastest iteration then generalized then ipairs and then numeric. The only time I see numeric being faster than 3 of those is when --!optimize 0, and sometime I see generalized beating next.
If I want speed and pure performance should I do table.move(t, 1, #t, 1, table.create(#t)) and use next? Or just do t[""] = nil because it doesn’t matter than much but it still doubles each time since it 2^n? Or just use a new table allocated, but then I will have to deal with like cleaning up references to the old table too