WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   General question about performance (https://www.wowinterface.com/forums/showthread.php?t=57267)

Lybrial 07-07-19 01:13 AM

General question about performance
 
Hi!

In many AddOns I see people doing stuff like that:

Lua Code:
  1. local _G = _G;
  2. local wipe = table.wipe;
  3. local remove = table.remove;
  4. ....

Whats the big advantage of that? Is it affecting the performance? The memory usage?
Is it for better readability? Just generally: Whats the reason for that?

This would all just create references, right?

SDPhantom 07-07-19 02:23 AM

The global environment is basically stored in a big table. Every time you want to read from this table you perform a table indexing operation, which takes a small amount of time. However, if code is run very often (think combat log events or every frame render), you may want to shave off as much time as possible. Local variables are stored as Lua registers, which are much quicker to access than the global environment.

Note: table.wipe and others like this cause more than one indexing operation as denoted by the dot. The first is retrieving table from the global environment and the second is to index wipe from table. Creating a local reference of this saves 2 indexing operations as a result.

Lybrial 07-07-19 02:40 AM

Quote:

Originally Posted by SDPhantom (Post 332777)
The global environment is basically stored in a big table. Every time you want to read from this table you perform a table indexing operation, which takes a small amount of time. However, if code is run very often (think combat log events or every frame render), you may want to shave off as much time as possible. Local variables are stored as Lua registers, which are much quicker to access than the global environment.

Note: table.wipe and others like this cause more than one indexing operation as denoted by the dot. The first is retrieving table from the global environment and the second is to index wipe from table. Creating a local reference of this saves 2 indexing operations as a result.

Thx for that explanation!


All times are GMT -6. The time now is 01:52 PM.

vBulletin © 2019, Jelsoft Enterprises Ltd
© 2004 - 2019 MMOUI