If we want to be nitpicky, the best approach is:
Code:
local meta = _R.Player
Garbage collection is the most expensive thing you can do in Lua, followed by invoking a function.
This is an obsessive micro-optimization that doesn't yield a great deal of result - it takes around one million executions to even reach the 1/5 of a second difference.
Code:
local t = { }
for k = 1, 1000000 do
t[ k ] = math.sin( k )
end
z = os.clock( )
for k = 1, 1000000 do
q = math.sin( k )
end
delta = os.clock( ) - z
z = os.clock( )
for k = 1, 1000000 do
q = t[ k ]
end
delta2 = os.clock( ) - z
print( string.format( "1,000,000 math.sin calls: ~%d miliseconds", delta * 1000 ) )
print( string.format( "1,000,000 table indexes: ~%d miliseconds", delta2 * 1000 ) )
The number is going to vary, of course, but I get output in the area of
Code:
1,000,000 math.sin calls: ~297 miliseconds
1,000,000 table indexes: ~108 miliseconds
The lesson is, class, that you should instead focus on not tripping the garbage collector as much as possible and recycle tables when you can to conserve performance. One of the fastest ways to trip it is to create a new table each frame for surface.DrawPoly, and thus at least three more subtables, as an example.