WoWInterface (
-   AddOn Help/Support (
-   -   Two addons showing high CPU usage, despite being small. (

Lesteryoung 09-20-17 10:09 PM

Two addons showing high CPU usage, despite being small.
Hi, I was having some fps issues so I downloaded an addon monitoring addon and noticed that two small addons were showing high CPU usage relative to their size. Could anyone take a look for me?


Lua Code:
  1. local SET_TEXT = TARGET .. ": |cff%02x%02x%02x%s|r"
  2. local MATCH_TEXT = "^" .. TARGET
  4. local last
  5. GameTooltip:HookScript("OnUpdate", function(self)
  6.     local name = UnitName("mouseovertarget")
  7.     if not name or name == "" or not self:GetUnit() then return end
  8.     last = name
  10.     local r, g, b
  11.     if UnitIsPlayer("mouseovertarget") then
  12.         local _, class = UnitClass("mouseovertarget")
  13.         local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  14.         r, g, b = color.r, color.g, color.b
  15.     else
  16.         r, g, b = GameTooltip_UnitColor("mouseovertarget")
  17.     end
  19.     for i = 2, self:NumLines() do
  20.         local line = _G["GameTooltipTextLeft"..i]
  21.         if strfind(line:GetText() or "", MATCH_TEXT) then
  22.             line:SetFormattedText(SET_TEXT, r * 255, g * 255, b * 255, name)
  23.             return self:Show()
  24.         end
  25.     end
  26.     self:AddLine(format(SET_TEXT, r * 255, g * 255, b * 255, name))
  27.     self:Show()
  28. end)
  30. GameTooltip:HookScript("OnTooltipSetUnit", function(GameTooltip)
  31.     local _, unit = GameTooltip:GetUnit()
  32.     if UnitIsPlayer(unit) then
  33.         local _, class = UnitClass(unit)
  34.         local color = class and (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  35.         if color then
  36.             local text = GameTooltipTextLeft1:GetText()
  37.             GameTooltipTextLeft1:SetFormattedText("|cff%02x%02x%02x%s|r", color.r * 255, color.g * 255, color.b * 255, text:match("|cff\x\x\x\x\x\x(.+)|r") or text)
  38.         end
  39.     end
  40. end)

Lua Code:
  1. hooksecurefunc('CooldownFrame_Set', function(self)
  2.         if self.currentCooldownType == COOLDOWN_TYPE_LOSS_OF_CONTROL then
  3.                 self:SetCooldown(0,0)          
  4.         end
  5. end)
  7. hooksecurefunc(getmetatable(CreateFrame('cooldown')).__index, 'SetCooldown', function(self)
  8.     self:SetDrawBling(false)
  9. end)

Torhal 09-21-17 03:34 AM

The size of the code doesn't matter as far as CPU is concerned - what it's actually doing, and how often, does.

I'm not sure what you're doing in the second snippet, so I cannot really comment. In the first snippet, however, you are performing calculations whenever the GameTooltip updates in its OnUpdate script. The OnUpdate script fires every time your screen is updated, so if you are getting 120FPS in game your code is running that many times per second.

semlar 09-21-17 01:11 PM


Originally Posted by Torhal (Post 325231)
I'm not sure what you're doing in the second snippet, so I cannot really comment.

This appears to actually be something I wrote a few years ago on the official forum to hide the cooldown that shows up on your abilities when you get crowd controlled.

The second part hides the little sparkle animation that plays on an action button when a cooldown finishes.

Lesteryoung 09-21-17 04:30 PM

The first snippet of code is using 80% of my CPU usage and it just keeps going up and up and up indefinitely.

Is something in it poorly written or is that just the nature of performing those functions? If the latter, I'll just scrap the addon.

semlar 09-21-17 04:55 PM

When you hook a script like GameTooltip:HookScript("OnUpdate"), its cpu usage is not measured correctly, it combines every other piece of code that's run along with the hooked function and counts that as the cpu used.

If you created your own frame to run the same OnUpdate script from, it would likely report a lower cpu usage.

That being said, this is not a very efficient function, and not something that needs to be run OnUpdate.

While I doubt this is using enough cpu to have an impact on your frame rate, the only time this code needs to run is you first mouse over a unit and when their target changes, so it could be moved into a function called by the OnTooltipSetUnit event, and a frame with RegisterUnitEvent('UNIT_TARGET', 'mouseover') on it.

First what you should do is just disable these 2 addons and see if it makes any difference in your frame rate, that will tell you if the problem is elsewhere.

All times are GMT -6. The time now is 12:29 AM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI