Quote:
Originally Posted by Fyrakin
(Post 23020)
It is a very fast changing environment, btw this particular function works fine no difference between live and pts. I made heavy changes during past week meantime testing it against pts and speeds are looking acceptable. Though it runs much smoother on live.
PS I also have noticed a faster garbage collection growth while using local variables. This is very worrying.
|
What merlight is trying to say is that finding the square root is a computationally expensive operation and should be avoided if at all possible. If sqrt( A ) < sqrt( B ), then A < B for distances.
I'd look at what else you're doing in the function because local variables by themselves won't noticeably increase GC time ( http://lua-users.org/wiki/OptimisingGarbageCollection ). In fact, it's generally an optimization to copy over to local from a global table, especially if you're going to access it frequently. ( http://lua-users.org/wiki/OptimisingUsingLocalVariables)
For example, looking up "FyrMM.currentMap.TrueMapSize" actually needs 3 table lookups: FyrMM in the Global table, currentMap in FyrMM, and TrueMapSize in currentMap. Bringing it to a local variable caches it so that when you access it the second or third time it's already present.
|