Optimization of array cycles in Lua

A common pattern is to use Lua tables as arrays: there is no other data structure so the choice is imposed. This does not usually pose any problem apart the fact you cannot store nil values in tables blindly.

However, when populating with millions of items, using Lua tables becomes a performance issue because the length operator has O(n) complexity. table.insert, the obvious candidate for such operation, has the worse performance. Directly using v[#v+1] avoids a call but still suffers from the O(n) problem. The proper solution is to avoid relying on the lengh operator by keeping a separate pointer or directly use the iterator variable of the cycle.