Looking for advices on how to structure my project and optimize performances

Generally, this:

for i=1,#t do

Is slower than this:

local num = #t
for i=1,num do

This is because you are recalculating the length of the table with each iteration.

You also want to avoid indexing a table over and over. This is bad:

table_laters_final[i].data[j][k].tile_id ...
table_laters_final[i].data[j][k].walkable ...

Better to prepare a variable like this:

local tile = table_laters_final[i].data[j][k]
tile.tile_id ...
tile.walkable ...

There are probably more issues that I’m not thinking of at the moment. Check out this excellent thread by @dlannan :

5 Likes