Okay, if anyone is interested, I decided to do up a quick test code, and looks like table.remove is actually at least 3 times faster then the replacement method. It appears the more items you have table.remove would be exponentially faster.
Not sure if this testing method is viable though as there is no other code running, but I assume if there was other code running both methods would slow down equally.
If the test method below is correct and table.remove is faster, that still does not solve the issue of performance when needing to remove an item. So I guess the only way to avoid performance issues is not to remove a table item nor replace it but as anaqim also suggested, to flag the table item. Of course this would require adjusting your actual game code to use flags instead of removing, and great care will be required to make sure you don’t forget the item is not removed.
local itemTable,tempTable,startTime -- table.remove method itemTable={1,2,3,4,5,6,7,8,9,10} startTime=system.getTimer() table.remove(itemTable,1) print("Table.remove method TIME:"..system.getTimer()-startTime..", #itemTable:"..tostring(#itemTable)) -- replacement method itemTable={1,2,3,4,5,6,7,8,9,10} startTime=system.getTimer() tempTable=itemTable;itemTable={} for j=2,#tempTable do itemTable[#itemTable+1]=tempTable[j] end print("Replacement method TIME:"..system.getTimer()-startTime..", #itemTable:"..tostring(#itemTable))
One last important thing to note, if you are removing more then 1 item from a table then it does appear the replacement method is faster exponentially. This can be tested by tweaking the above testing code to below:
local itemTable,tempTable,startTime -- table.remove method itemTable={1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0} startTime=system.getTimer() for j=1,10 do table.remove(itemTable,j) end print("Table.remove method TIME:"..system.getTimer()-startTime..", #itemTable:"..tostring(#itemTable)) -- replacement method itemTable={1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0} startTime=system.getTimer() tempTable=itemTable;itemTable={} for j=11,#tempTable do itemTable[#itemTable+1]=tempTable[j] end print("Replacement method TIME:"..system.getTimer()-startTime..", #itemTable:"..tostring(#itemTable))
Appreciate the feedback and hope this may help others. Cheers.