View Single Post
09-26-16, 01:39 AM   #28
Kagura
A Fallenroot Satyr
Join Date: Nov 2008
Posts: 21
Originally Posted by SDPhantom View Post
If you're interested in trimming down your CPU usage, the most expensive Lua operations are function calls followed by table indexing. Indexing operations are what surprise a lot of people because of how much they can stack up. Accessing a global is an indexing operation on Lua's environment table. Metatables add at least two indexing operations each whenever they need to be accessed if __index is another table. If it's a function, then it's an indexing operation plus the function call.

You should also keep an eye on memory usage. Garbage collection cycles are notorious for causing large amounts of framerate drops. Because of this, avoid creating dynamic tables and functions and releasing them very often.
I linked to some resources in another reply, but yes: I am very well aware of this. The difference though is: trying to optimize code that gets run once vs trying to optimize code that gets run every frame. 100 extra function calls per lifetime of the application isn't something to worry about imho.

I do things like in : https://gist.github.com/Nimaear/e267...311b6f70eadd17 where I dynamically load addons depending on an event to speed up boot times. I personally think the added extra memory (around 23k) from this is nothing compared to the benefit you get: almost instant load screens.

I don't create any dynamic tables in code that gets rerun more than once unless I have to. I do admit that this is a really hard area to try to automate for a compiler.

Last edited by Kagura : 09-26-16 at 01:50 AM.
  Reply With Quote