Thread Tools Display Modes
09-20-17, 10:09 PM   #1
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
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?

Thanks.

1.
Lua Code:
  1. local SET_TEXT = TARGET .. ": |cff%02x%02x%02x%s|r"
  2. local MATCH_TEXT = "^" .. TARGET
  3.  
  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
  9.  
  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
  18.  
  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)
  29.  
  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)

2.
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)
  6.  
  7. hooksecurefunc(getmetatable(CreateFrame('cooldown')).__index, 'SetCooldown', function(self)
  8.     self:SetDrawBling(false)
  9. end)
  Reply With Quote
09-21-17, 03:34 AM   #2
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
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.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
09-21-17, 01:11 PM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Torhal View Post
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.

Last edited by semlar : 09-21-17 at 01:16 PM.
  Reply With Quote
09-21-17, 04:30 PM   #4
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
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.
  Reply With Quote
09-21-17, 04:55 PM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
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.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Two addons showing high CPU usage, despite being small.

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off