Well, assuming that's what's causing the problem, it's likely only doing so because you're calling it potentially hundreds of times per second in combat, in response to UNIT_AURA (multiply that by the number of units you use this element on). You should keep track of whether the timer is already running, and if so, just return out if the buff is still active.
There are also some questionable bits in your code; for example:
Code:
local UnitDebuff, index = UnitDebuff, 0
while (true) do
index = index + 1
local name, _, icon, _, _, duration, expirationTime, _, _, _, spellId = (UnitDebuff or UnitBuff)(unit, index)
For one, I'd either upvalue UnitDebuff outside of your event handler, or don't bother upvaluing at all. For two, this code can never fall back to using UnitBuff, so you should probably get rid of that, or fix the rest of the code if it's supposed to use UnitBuff under some circumstances.
Code:
UnitDebuff = nil
index = 0
You don't need to manually un-set your (local) variables in Lua; they're automatically garbage-collected once they go out of scope.
I'd rewrite that update function like so:
Code:
local UnitDebuff = UnitDebuff
local Update = function(self, event, unit)
if (self.unit ~= unit) then
return
end
local pt = self.PortraitTimer
local showing = pt:IsShown()
for index = 1, 40 do
local name, _, icon, _, _, duration, expirationTime, _, _, _, spellId = UnitDebuff(unit, index)
if not name then
break
end
if PortraitTimerDB[spellId] then
if not showing then
UpdateIcon(pt, icon, duration, expirationTime)
pt:Show()
if self.CombatFeedbackText then
self.CombatFeedbackText.maxAlpha = 0
end
end
return
end
end
if showing then
pt:Hide()
end
if self.CombatFeedbackText then
self.CombatFeedbackText.maxAlpha = 1
end
end