View Single Post
05-17-19, 06:20 AM   #3
Pindrought
A Defias Bandit
Join Date: May 2019
Posts: 2
Originally Posted by myrroddin View Post
If the addon uses or calls those functions a lot, like in a loop that runs hundreds or thousands of times, or if the functions are tied to event handlers that fire all the time, then creating local references will trade RAM/memory for CPU efficiency.
Lua Code:
  1. -- psuedocode example
  2. local n = 1
  3. do
  4.     print("The value of n is: ", n)
  5. until n == 100000
print will be called 100,000 times, each one a lookup on the global table. That is not efficient.
Lua Code:
  1. local print = print -- looked up once, and kept in memory
  2. local n = 1
  3. do
  4.     print("The value of n is: ", n)
  5. until n == 100000
Such a good explanation! Thank you!
  Reply With Quote