Quantcast WoWInterface - View Single Post - How do I make this options list faster?
View Single Post
06-03-19, 01:29 PM   #7
jeruku
A Chromatic Dragonspawn
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 198
Use what SDPhantom said to dissuade everyone.

Personally I'd use more tables than concatenations since memory references take both CPU cycles and RAM, it can actually take less time just to use an extra CPU cycle.
Lua Code:
  1. PBA.APBUseBlizz[BarID] -- two simple table lookups
  2. --instead of PBA['APBUseBlizz' .. BarID] -- You create two strings in RAM, access both, and do a table lookup


Scope helps, creating new locals every single time in a loop creates them that many times. And garbage collection isn't guaranteed to work immediately after the function is resolved.
Lua Code:
  1. local AltPowerType, MinPower, PowerName, PowerTooltip, ZoneName, _ -- _ is still a variable and is a common global leak in addons
  2. for BarID = 1, 10000 do
  3.     AltPowerType, MinPower, _, _, _, _, _, _, _, _, PowerName, PowerTooltip = GetAlternatePowerInfoByID(BarID)
  4.     ZoneName = APBUsed[BarID]


Making If statements with a common denominator helps
Lua Code:
  1. local Index
  2. --scoping mentioned above
  3. if AltPowerType then
  4.     if TableName ~= 'APB'  and APBUseBlizz[BarID] then
  5.         Index = APBUseBlizz[BarID]
  6.     else
  7.         PBA.APBUseBlizz[BarID] = {}
  8.     end
  9. end
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison

Last edited by jeruku : 06-03-19 at 05:47 PM. Reason: Thanks, SDPhantom, I learned something new.
  Reply With Quote