WoWInterface - View Single Post - Registering for all events / asynchronous code execution
View Single Post
06-30-20, 06:21 AM   #8
A Pyroguard Emberseer
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,991
Originally Posted by LudiusMaximus View Post
That's interesting. Are you saying that calling a function is significantly more taxing than it would be to execute the function's code "inline"?
All Lua operations are relatively quick, but compared to C code and being called literally thousands of times, this adds up. Also this is comparing simple operations like creating a table, assigning a variable, indexing, etc. A single line of code often has many of these operations in it.

Originally Posted by LudiusMaximus View Post
When I code I try to use functions wherever I can to avoid writing the same code more than once. Does this make my code less efficient as more functions are called?
It's a balancing act between speed, readability, and maintainability. You shouldn't have separate functions for code that's only being run for one place or be calling a function that you know does nothing in a situation you can avoid.

The overall goal is to have code that's easy to read and maintain, but not be too wasteful of CPU time if you can help it.

Originally Posted by LudiusMaximus View Post
Another thing I was wondering: Is it more efficient to have one frame listening to several events and decide what to do depending on the event within the one OnEvent function. Or to have several frames each listening to only one event? Or does this make no difference?
This is another balancing act. It's weighing between having many frames call one function independently or having one frame loop through a list of others, calling an iterator in a for loop to retrieve each one. Comparing the two, I would say it makes no difference.
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 06-30-20 at 07:00 AM.
  Reply With Quote