Quantcast WoWInterface - View Single Post - Minimap Coordinates Memory Usage Optimization
View Single Post
07-10-19, 02:06 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,889
Originally Posted by jeruku View Post
Lua Code:
  1. -- Move global functions into the frames table; you could also make them locals, like below, but I prefer this method.
  2. --     local GetWorldPosFromMapPos = C_Map.GetWorldPosFromMapPos
  3. tMinimapCoordsFrame.MapRects =  {}
  4. tMinimapCoordsFrame.UnitPosition =  UnitPosition
  5. tMinimapCoordsFrame.GetWorldPosFromMapPos =  C_Map.GetWorldPosFromMapPos
  6. tMinimapCoordsFrame.CreateVector2D =  CreateVector2D
Moving local references to globals into a table defeats the purpose of making them in the first place, which is to save on indexing operations. You run the same number of these operations pulling them from your table as you would calling them as globals.



Originally Posted by jeruku View Post
Lua Code:
  1. --    I dislike strings in OnUpdate; again, personal preference.
  2.  
  3. tMinimapCoordsFrame.FromattedString = '%.1f, %.1f'
  4. tMinimapCoordsFrame.PlayerToken = 'player'
These actually create indexing operations in the following OnUpdate script as opposed to them being stored as a part of the function binary as a constant. All literal values are constants referred to when used in an expression. In the long run, this actually slows down the function instead of offering any performance boost.



Originally Posted by jeruku View Post
Lua Code:
  1. local function Blank_OnUpdate() end
  2. local OnUpdate = Blank_OnUpdate
  3.  
  4. tMinimapCoordsFrame:HookScript('OnUpdate', OnUpdate)
  5.  
  6. --  Getting the mapID every OnUpdate is rather inefficient, get it when it changes/loads
  7. local GetBestMapForUnit = C_Map.GetBestMapForUnit
  8. tMinimapCoordsFrame:HookScript('OnEvent', function(self, event, ...)
  9.     if event == 'PLAYER_STARTED_MOVING' then --  Self explanatory event
  10.         OnUpdate = Do_OnUpdate
  11.     elseif event == 'PLAYER_STOPPED_MOVING' then
  12.         OnUpdate = Blank_OnUpdate
  13.     elseif event == 'ZONE_CHANGED' or event == 'ZONE_CHANGED_INDOORS' or event == 'ZONE_CHANGED_NEW_AREA' or event == 'PLAYER_ENTERING_WORLD'  then
  14.         self.mapID = GetBestMapForUnit('player')
  15.                 Do_OnUpdate(self, self.mapID)
  16.     end
  17. end)
This way of swapping OnUpdate scripts doesn't work at all. It doesn't magically tell the function to watch OnUpdate for changes, it just ends up grabbing Blank_OnUpdate() on initialization and further changes in the event script does nothing. Since the OP used :SetScript() to assign the function in the first place, it's safe to assume you can run :SetScript("OnUpdate",nil) to clear and set it again when necessary. Otherwise, you can set an upvalue to flag and have the script check it when it's to run.
__________________
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 : 07-10-19 at 02:32 PM.
  Reply With Quote