View Single Post
08-27-15, 02:41 AM   #14
Nevcairiel
Premium Member
Premium Member
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 63
Lua Code:
  1. -- unregister and store all WORLD_MAP_UPDATE registrants, to avoid excess processing when
  2. -- retrieving info from stateful map APIs
  3. local wmuRegistry
  4. local function UnregisterWMU()
  5.     wmuRegistry = {GetFramesRegisteredForEvent("WORLD_MAP_UPDATE")}
  6.     for _, frame in ipairs(wmuRegistry) do
  7.         frame:UnregisterEvent("WORLD_MAP_UPDATE")
  8.     end
  9. end
  10.  
  11. -- restore WORLD_MAP_UPDATE to all frames in the registry
  12. local function RestoreWMU()
  13.     assert(wmuRegistry)
  14.     for _, frame in ipairs(wmuRegistry) do
  15.         frame:RegisterEvent("WORLD_MAP_UPDATE")
  16.     end
  17.     wmuRegistry = nil
  18. end

Call UnregisterWMU before doing map things, call RestoreWMU when you are done (and preferably after you restored the original map again, so addons dont get confused)
Obviously this should be used with care and only in singular code blocks, so that the event doesn't stay unregistered for longer than your code needs to run, and addons dont break.

I could totally imagine that one of the reasons for these performance optimizations referenced in the commit I linked earlier was an addon doing map changes without such a trick. For example, HandyNotes (which is actually the reason for this thread), had quite a few bugs which caused excessive map changes in some areas (mostly due to the broken Astrolabe library) - but a lot of map functionality in HandyNotes has been re-written and cleaned up, and Astrolabe replaced.

Last edited by Nevcairiel : 08-27-15 at 03:00 AM.
  Reply With Quote