Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization for running trigger function less often #5079

Merged
merged 6 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 54 additions & 52 deletions WeakAuras/GenericTrigger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -793,24 +793,33 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2
return updateTriggerState;
end

---ScanEvents may receive composed events like `event:spellId`
---For system profiling we want extract the event
---@param composedEvent string
---@return string
local function getGameEventFromComposedEvent(composedEvent)
local separatorPosition = composedEvent:find(":", 1, true)
return separatorPosition == nil and composedEvent or composedEvent:sub(1, separatorPosition - 1)
end

---@param event string
---@param arg1? any
---@param arg2? any
---@param ... any
function WeakAuras.ScanEvents(event, arg1, arg2, ...)
local orgEvent = event;
Private.StartProfileSystem("generictrigger " .. orgEvent )
local system = getGameEventFromComposedEvent(event)
Private.StartProfileSystem("generictrigger " .. system)
local event_list = loaded_events[event];
if (not event_list) then
Private.StopProfileSystem("generictrigger " .. orgEvent )
Private.StopProfileSystem("generictrigger " .. system)
return
end
if(event == "COMBAT_LOG_EVENT_UNFILTERED") then
local arg1, arg2 = CombatLogGetCurrentEventInfo();

event_list = event_list[arg2];
if (not event_list) then
Private.StopProfileSystem("generictrigger " .. orgEvent )
Private.StopProfileSystem("generictrigger " .. system)
return;
end
WeakAuras.ScanEventsInternal(event_list, event, CombatLogGetCurrentEventInfo());
Expand All @@ -824,7 +833,7 @@ function WeakAuras.ScanEvents(event, arg1, arg2, ...)
else
WeakAuras.ScanEventsInternal(event_list, event, arg1, arg2, ...);
end
Private.StopProfileSystem("generictrigger " .. orgEvent )
Private.StopProfileSystem("generictrigger " .. system)
end

---@param event string
Expand Down Expand Up @@ -1309,6 +1318,15 @@ function LoadEvent(id, triggernum, data)
loaded_events[event][id][triggernum] = data;
end
end
-- this special internal_events function is run when aura load instead of when it is added
if data.loadInternalEventFunc then
local internal_events = data.loadInternalEventFunc(data.trigger)
for index, event in pairs(internal_events) do
loaded_events[event] = loaded_events[event] or {};
loaded_events[event][id] = loaded_events[event][id] or {};
loaded_events[event][id][triggernum] = data;
end
end
if data.unit_events then
local includePets = data.includePets
for unit, events in pairs(data.unit_events) do
Expand Down Expand Up @@ -1529,7 +1547,7 @@ function GenericTrigger.Add(data, region)
local trigger_subevents = {};
---@type boolean|string|table
local force_events = false;
local durationFunc, overlayFuncs, nameFunc, iconFunc, textureFunc, stacksFunc, loadFunc;
local durationFunc, overlayFuncs, nameFunc, iconFunc, textureFunc, stacksFunc, loadFunc, loadInternalEventFunc;
local tsuConditionVariables;
local prototype = nil
local automaticAutoHide
Expand Down Expand Up @@ -1569,6 +1587,7 @@ function GenericTrigger.Add(data, region)
textureFunc = prototype.textureFunc;
stacksFunc = prototype.stacksFunc;
loadFunc = prototype.loadFunc;
loadInternalEventFunc = prototype.loadInternalEventFunc;

if (prototype.overlayFuncs) then
overlayFuncs = {};
Expand Down Expand Up @@ -1771,6 +1790,7 @@ function GenericTrigger.Add(data, region)
event = trigger.event,
events = trigger_events,
internal_events = internal_events,
loadInternalEventFunc = loadInternalEventFunc,
force_events = force_events,
unit_events = trigger_unit_events,
includePets = includePets,
Expand Down Expand Up @@ -1858,25 +1878,6 @@ do
end
end

local combatLogUpgrade = {
["sourceunit"] = "sourceUnit",
["source"] = "sourceName",
["destunit"] = "destUnit",
["dest"] = "destName"
}

local oldPowerTriggers = {
["Combo Points"] = 4,
["Holy Power"] = 9,
["Insanity"] = 13,
["Chi Power"] = 12,
["Astral Power"] = 8,
["Maelstrom"] = 11,
["Arcane Charges"] = 16,
["Fury"] = 17,
["Pain"] = 18,
["Shards"] = 7,
}

--#############################
--# Support code for triggers #
Expand Down Expand Up @@ -2395,7 +2396,7 @@ do
cdReadyFrame:RegisterEvent("SPELL_UPDATE_USABLE")
cdReadyFrame:RegisterEvent("UNIT_SPELLCAST_SENT");
cdReadyFrame:RegisterEvent("BAG_UPDATE_DELAYED");
cdReadyFrame:RegisterEvent("UNIT_INVENTORY_CHANGED")
cdReadyFrame:RegisterUnitEvent("UNIT_INVENTORY_CHANGED", "player")
cdReadyFrame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED");
cdReadyFrame:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN");
cdReadyFrame:RegisterEvent("SPELLS_CHANGED");
Expand Down Expand Up @@ -2762,14 +2763,14 @@ do
itemCdDurs[id] = nil;
itemCdExps[id] = nil;
itemCdEnabled[id] = 1;
WeakAuras.ScanEvents("ITEM_COOLDOWN_READY", id);
WeakAuras.ScanEvents("ITEM_COOLDOWN_READY:" .. id, id);
end

local function ItemSlotCooldownFinished(id)
itemSlotsCdHandles[id] = nil;
itemSlotsCdDurs[id] = nil;
itemSlotsCdExps[id] = nil;
WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_READY", id);
WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_READY:" .. id, id);
end

---@type fun()
Expand Down Expand Up @@ -2964,7 +2965,7 @@ do
end

if changed and not WeakAuras.IsPaused() then
WeakAuras.ScanEvents("SPELL_COOLDOWN_CHANGED", id)
WeakAuras.ScanEvents("SPELL_COOLDOWN_CHANGED:" .. id, id)
end
end
end
Expand Down Expand Up @@ -3010,21 +3011,21 @@ do

if not WeakAuras.IsPaused() then
if nowReady then
WeakAuras.ScanEvents("SPELL_COOLDOWN_READY", id);
WeakAuras.ScanEvents("SPELL_COOLDOWN_READY:" .. id, id)
end

if changed or chargesChanged then
WeakAuras.ScanEvents("SPELL_COOLDOWN_CHANGED", id);
WeakAuras.ScanEvents("SPELL_COOLDOWN_CHANGED:" .. id, id)
end

if (chargesDifference ~= 0 ) then
WeakAuras.ScanEvents("SPELL_CHARGES_CHANGED", id, chargesDifference, charges or spellCount or 0);
WeakAuras.ScanEvents("SPELL_CHARGES_CHANGED:" .. id, id, chargesDifference, charges or spellCount or 0);
end
end
end

---@type fun(runeDuration)
function Private.CheckSpellCooldows(runeDuration)
function Private.CheckSpellCooldowns(runeDuration)
for id, _ in pairs(spells) do
Private.CheckSpellCooldown(id, runeDuration)
end
Expand Down Expand Up @@ -3066,7 +3067,7 @@ do
itemCdExps[id] = endTime;
itemCdHandles[id] = timer:ScheduleTimerFixed(ItemCooldownFinished, endTime - time, id);
if not WeakAuras.IsPaused() then
WeakAuras.ScanEvents("ITEM_COOLDOWN_STARTED", id)
WeakAuras.ScanEvents("ITEM_COOLDOWN_STARTED:" .. id, id)
end
itemCdEnabledChanged = false;
elseif(itemCdExps[id] ~= endTime) then
Expand All @@ -3078,7 +3079,7 @@ do
itemCdExps[id] = endTime;
itemCdHandles[id] = timer:ScheduleTimerFixed(ItemCooldownFinished, endTime - time, id);
if not WeakAuras.IsPaused() then
WeakAuras.ScanEvents("ITEM_COOLDOWN_CHANGED", id)
WeakAuras.ScanEvents("ITEM_COOLDOWN_CHANGED:" .. id, id)
end
itemCdEnabledChanged = false;
end
Expand All @@ -3096,7 +3097,7 @@ do
end
end
if (itemCdEnabledChanged and not WeakAuras.IsPaused()) then
WeakAuras.ScanEvents("ITEM_COOLDOWN_CHANGED", id);
WeakAuras.ScanEvents("ITEM_COOLDOWN_CHANGED:" .. id, id);
end
end
end
Expand All @@ -3122,7 +3123,7 @@ do
itemSlotsCdExps[id] = endTime;
itemSlotsCdHandles[id] = timer:ScheduleTimerFixed(ItemSlotCooldownFinished, endTime - time, id);
if not WeakAuras.IsPaused() then
WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_STARTED", id)
WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_STARTED:" .. id, id)
end
elseif(itemSlotsCdExps[id] ~= endTime) then
-- Cooldown is now different
Expand All @@ -3133,7 +3134,7 @@ do
itemSlotsCdExps[id] = endTime;
itemSlotsCdHandles[id] = timer:ScheduleTimerFixed(ItemSlotCooldownFinished, endTime - time, id);
if not WeakAuras.IsPaused() then
WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_CHANGED", id)
WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_CHANGED:" .. id, id)
end
end
elseif(duration > 0) then
Expand All @@ -3152,7 +3153,7 @@ do
local newItemId = GetInventoryItemID("player", id);
if (itemId ~= newItemId) then
if not WeakAuras.IsPaused() then
WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_ITEM_CHANGED")
WeakAuras.ScanEvents("ITEM_SLOT_COOLDOWN_ITEM_CHANGED:" .. id, id)
end
itemSlots[id] = newItemId or 0;
end
Expand All @@ -3163,7 +3164,7 @@ do
function Private.CheckCooldownReady()
CheckGCD();
local runeDuration = Private.CheckRuneCooldown();
Private.CheckSpellCooldows(runeDuration);
Private.CheckSpellCooldowns(runeDuration);
Private.CheckItemCooldowns();
Private.CheckItemSlotCooldowns();
end
Expand Down Expand Up @@ -3333,18 +3334,19 @@ do
spellActivationFrame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW");
spellActivationFrame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE");
spellActivationFrame:SetScript("OnEvent", function(self, event, spell)
Private.StartProfileSystem("generictrigger");
Private.StartProfileSystem("generictrigger spell activation");
local spellName = Private.ExecEnv.GetSpellName(spell)
if (spellActivationSpells[spell] or spellActivationSpells[spellName]) then
local active = (event == "SPELL_ACTIVATION_OVERLAY_GLOW_SHOW")
spellActivationSpellsCurrent[spell] = active
spellActivationSpellsCurrent[spellName] = active
if not WeakAuras.IsPaused() then
WeakAuras.ScanEvents("WA_UPDATE_OVERLAY_GLOW", spell)
WeakAuras.ScanEvents("WA_UPDATE_OVERLAY_GLOW:" .. spell, spell)
WeakAuras.ScanEvents("WA_UPDATE_OVERLAY_GLOW:" .. spellName, spell)
end
end

Private.StopProfileSystem("generictrigger");
Private.StopProfileSystem("generictrigger spell activation");
end);
end

Expand Down Expand Up @@ -3646,7 +3648,7 @@ do
function WeakAuras.TenchInit()
if not(tenchFrame) then
tenchFrame = CreateFrame("Frame");
tenchFrame:RegisterEvent("UNIT_INVENTORY_CHANGED");
tenchFrame:RegisterUnitEvent("UNIT_INVENTORY_CHANGED", "player");
tenchFrame:RegisterEvent("PLAYER_ENTERING_WORLD");
if WeakAuras.IsClassicEra() then
tenchFrame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED");
Expand Down Expand Up @@ -3698,7 +3700,7 @@ do
end

local function tenchUpdate()
Private.StartProfileSystem("generictrigger");
Private.StartProfileSystem("generictrigger temporary enchant");
local _, mh_rem, oh_rem, rw_rem
_, mh_rem, mh_charges, mh_EnchantID, _, oh_rem, oh_charges, oh_EnchantID, _, rw_rem, rw_charges, rw_EnchantID = GetWeaponEnchantInfo();
local time = GetTime();
Expand Down Expand Up @@ -3738,13 +3740,13 @@ do
end
end
WeakAuras.ScanEvents("TENCH_UPDATE");
Private.StopProfileSystem("generictrigger");
Private.StopProfileSystem("generictrigger temporary enchant");
end

tenchFrame:SetScript("OnEvent", function()
Private.StartProfileSystem("generictrigger");
Private.StartProfileSystem("generictrigger temporary enchant");
timer:ScheduleTimer(tenchUpdate, 0.1);
Private.StopProfileSystem("generictrigger");
Private.StopProfileSystem("generictrigger temporary enchant");
end);

tenchUpdate();
Expand Down Expand Up @@ -3774,9 +3776,9 @@ do
petFrame = CreateFrame("Frame");
petFrame:RegisterUnitEvent("UNIT_PET", "player")
petFrame:SetScript("OnEvent", function(event, unit)
Private.StartProfileSystem("generictrigger")
Private.StartProfileSystem("generictrigger pet update")
WeakAuras.ScanEvents("PET_UPDATE", "pet")
Private.StopProfileSystem("generictrigger")
Private.StopProfileSystem("generictrigger pet update")
end)
end
end
Expand Down Expand Up @@ -3882,7 +3884,7 @@ do
local playerMovingFrame = nil

local function PlayerMoveUpdate()
Private.StartProfileSystem("generictrigger");
Private.StartProfileSystem("generictrigger player moving");
local moving = IsPlayerMoving()
if (playerMovingFrame.moving ~= moving or playerMovingFrame.moving == nil) then
playerMovingFrame.moving = moving
Expand All @@ -3894,7 +3896,7 @@ do
playerMovingFrame.speed = speed
WeakAuras.ScanEvents("PLAYER_MOVE_SPEED_UPDATE")
end
Private.StopProfileSystem("generictrigger");
Private.StopProfileSystem("generictrigger player moving");
end

---@private
Expand Down
33 changes: 29 additions & 4 deletions WeakAuras/Profiling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -446,17 +446,17 @@ end
local COLUMN_INFO = {
{
title = L["Name"],
width = 300,
width = 1,
attribute = "name",
},
{
title = L["Time"],
width = 80,
width = 100,
attribute = "time",
},
{
title = L["Spike"],
width = 80,
width = 100,
attribute = "spike",
},
}
Expand All @@ -475,6 +475,7 @@ local modes = {
}
WeakAurasProfilingMixin = {}

local MinPanelWidth, MinPanelHeight = 500, 300
function WeakAurasProfilingMixin:OnShow()
if self.initialised then
return
Expand All @@ -483,7 +484,8 @@ function WeakAurasProfilingMixin:OnShow()

ButtonFrameTemplate_HidePortrait(self)
self:SetTitle(L["WeakAuras Profiling"])
self:SetSize(500, 300)
self:SetSize(MinPanelWidth, MinPanelHeight)
self.ResizeButton:Init(self, MinPanelWidth, MinPanelHeight);
self.mode = 1
UIDropDownMenu_SetText(self.buttons.modeDropDown, modes[1])

Expand Down Expand Up @@ -519,6 +521,29 @@ function WeakAurasProfilingMixin:OnShow()

self.ColumnDisplay:LayoutColumns(COLUMN_INFO)

-- LayoutColumns doesn't handle resizable columns, fix it
local headers = {}
for header in self.ColumnDisplay.columnHeaders:EnumerateActive() do
headers[header:GetID()] = header
end
local prevHeader
for i, header in ipairs_reverse(headers) do
header:ClearAllPoints()
local info = COLUMN_INFO[i]
if info.width ~= 1 then
header:SetWidth(info.width)
end
if prevHeader == nil then
header:SetPoint("BOTTOMRIGHT", -25, 1)
else
header:SetPoint("BOTTOMRIGHT", prevHeader, "BOTTOMLEFT", 2, 0)
end
if i == 1 then
header:SetPoint("BOTTOMLEFT", 3, 0)
end
prevHeader = header
end

local view = CreateScrollBoxListLinearView()
view:SetElementInitializer("WeakAurasProfilingLineTemplate", function(frame, elementData)
frame:Init(elementData)
Expand Down
Loading