View Single Post
04/28/14, 10:54 PM   #7
SpecialK
Join Date: Apr 2014
Posts: 6
Maybe too many abuses of "OnFrame" handlers.
Probably a lot of devs don't realize it gets ticked at the full frame/game-loop rate!

Do you really need your addon to be update 50-100 times a second?
Probably not..
If you have your stuff running at update speed your are basically competing with everything else
the client game loop is doing.

What devs could do here is use some kind of timer/limiter and, or, spin count to reduce the
frequency of updates.
I.E:
Lua Code:
  1. local _LastUpdateTime = -1
  2. local function _OnUpdate()
  3.     local Time = GetFrameTimeMilliseconds()
  4.     if (Time >= _LastUpdateTime) then    
  5.         _LastUpdateTime = (Time + 100)
  6.  
  7.        ... Do your code here..
  8.     end
  9. end

I saw this problem with the original "ZrMM". My FPS dropped around 10 with it enabled.
I added a limiter to it's update method like above and the problem was gone.
With a 100ms delay it's updating around 10x a second (vrs 50-75 fps for my avg frame rate).
Mind you with too much of a delay (like 500ms, 1/2 second), it made the plugin's update too jerky so
you have to find a trade-off somewhere around the ideal.

There is an updated ZrMM now (different author) that fixed this, added some features, and fixed bugs et al.

Better yet there is the "EVENT_MANAGER:RegisterForUpdate" API method that will tick at what ever delay you set it to!
No need to do a built in limiter like I first did.
Example:
Lua Code:
  1. -- Setup my update handler to tick about every 200ms (5x a second)
  2. EVENT_MANAGER:RegisterForUpdate("MyAddOnUpdate", 200, _OnUpdate)

If only everyone (that doesn't really need an update every frame) used this API instead..
  Reply With Quote