From 2a0d607bcd473394989a2f2a723fd13d9ed1788a Mon Sep 17 00:00:00 2001 From: Bluewhale1337 <295648290+Bluewhale1337@users.noreply.github.com> Date: Sun, 4 Oct 2026 17:54:00 +0200 Subject: [PATCH] fix: improve performance and safety with null checks and talent rank caching --- HealBot.lua | 1 + HealBotBlue.toc | 2 +- HealBot_Controller_Events.lua | 2 ++ HealBot_Controller_Spells.lua | 39 ++++++++++++++++------------------- README.md | 1 + 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/HealBot.lua b/HealBot.lua index 7c37104..93e6548 100644 --- a/HealBot.lua +++ b/HealBot.lua @@ -271,6 +271,7 @@ end -- HealBot_FindUnitID: Finds a unit token for a given player name. function HealBot_FindUnitID(unitname) + if not unitname then return nil end return HealBot_NameToUnitID[unitname] end diff --git a/HealBotBlue.toc b/HealBotBlue.toc index 30b9bda..4a508a7 100644 --- a/HealBotBlue.toc +++ b/HealBotBlue.toc @@ -1,6 +1,6 @@ ## Interface: 11200 ## Title: HealBotBlue -## Version: 1.7.3 +## Version: 1.7.4 ## Author: Bluewhale ## Notes: Raidframe replacement for healing, decursing, resource tracking and buffing with optional support for SuperWow, ClassicAPI, UnitXP_SP3 and Nampower. ## SavedVariablesPerCharacter: HealBot_Config diff --git a/HealBot_Controller_Events.lua b/HealBot_Controller_Events.lua index 71dfc9d..c096839 100644 --- a/HealBot_Controller_Events.lua +++ b/HealBot_Controller_Events.lua @@ -565,6 +565,7 @@ end -- HealBot_OnEvent_TalentsChanged: Internal utility: HealBot_OnEvent_TalentsChanged function HealBot_OnEvent_TalentsChanged(this, arg1) HealBot_AddDebug("HB: TalentsChanged"); + if HealBot_UpdateTalentRanks then HealBot_UpdateTalentRanks() end end -- HealBot_OnEvent_PlayerEnteringWorld: Internal utility: HealBot_OnEvent_PlayerEnteringWorld @@ -574,6 +575,7 @@ function HealBot_OnEvent_PlayerEnteringWorld(this) if HealBot_ApplyRefreshHook then HealBot_ApplyRefreshHook() end + if HealBot_UpdateUnitIDCache then HealBot_UpdateUnitIDCache() end end -- HealBot_OnEvent_SpellcastStart: Internal utility: HealBot_OnEvent_SpellcastStart diff --git a/HealBot_Controller_Spells.lua b/HealBot_Controller_Spells.lua index e6dd71a..82ee3a6 100644 --- a/HealBot_Controller_Spells.lua +++ b/HealBot_Controller_Spells.lua @@ -53,6 +53,7 @@ end -- HealBot_GetSpellId: Internal utility: HealBot_GetSpellId function HealBot_GetSpellId(spell) + if not spell then return nil end return HealBot_SpellNameToId[spell] end @@ -210,18 +211,6 @@ end -- HealBot_StartCasting: Initiates spell cast and broadcasts incoming heal. function HealBot_StartCasting(spell, target, ttype) HealBot_CastFailed = false; - - -- Extract base spell for internal tracking - local baseSpell = spell - local parenIndex = string.find(spell, " %(") - if parenIndex then - baseSpell = string.sub(spell, 1, parenIndex - 1) - else - parenIndex = string.find(spell, "%(") - if parenIndex then - baseSpell = string.sub(spell, 1, parenIndex - 1) - end - end HealBot_CastSpellByName(spell); if ( SpellCanTargetUnit(target) ) then @@ -236,11 +225,11 @@ function HealBot_StartCasting(spell, target, ttype) end end - if ttype == "fired" and HealBot_Spells[baseSpell] then + if ttype == "fired" and HealBot_Spells[spell] then if not HealBot_CastFailed then - HealBot_CastingSpell = baseSpell; + HealBot_CastingSpell = spell; HealBot_CastingTarget = target; - HealBot_Process_HealValue(baseSpell, target); + HealBot_Process_HealValue(spell, target); HealBot_AnnounceCast(spell, target); end end @@ -654,17 +643,24 @@ function HealBot_RecalcSpells() HealBot_RecalcParty(); end --- HealBot_GetTalentRank: Internal utility: HealBot_GetTalentRank -function HealBot_GetTalentRank(talentName) +HealBot_TalentRanks = {} + +function HealBot_UpdateTalentRanks() + HealBot_TalentRanks = {} for t = 1, GetNumTalentTabs() do for i = 1, GetNumTalents(t) do - local nameTalent, icon, tier, column, currRank, maxRank = GetTalentInfo(t, i); - if nameTalent == talentName then - return currRank; + local nameTalent, icon, tier, column, currRank, maxRank = GetTalentInfo(t, i) + if nameTalent then + HealBot_TalentRanks[nameTalent] = currRank end end end - return 0; +end + +-- HealBot_GetTalentRank: Internal utility: HealBot_GetTalentRank +function HealBot_GetTalentRank(talentName) + if not next(HealBot_TalentRanks) then HealBot_UpdateTalentRanks() end + return HealBot_TalentRanks[talentName] or 0 end -- HealBot_SpiBonus: Internal utility: HealBot_SpiBonus @@ -699,6 +695,7 @@ end -- HealBot_InitSpells: Scans spellbook to find available heals. function HealBot_InitSpells() + HealBot_CacheSpellIDs() local id = 1 local cnt = 0; local class = HealBot_UnitClass("player") diff --git a/README.md b/README.md index ca8568c..565fa39 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Default installation path: `C:\Program Files\World of Warcraft\Interface\AddOns\ * **Performance Fix - Spell Lookup** - Fixed a massive CPU drain and garbage generation issue where the entire spellbook was linearly scanned every frame per unit. Spell IDs are now cached via O(1) dictionary lookup on login and talent/spell changes. * **Performance Fix - Unit Hash Lookup** - Eliminated heavy C-API calls to `UnitName()` during incoming heals by caching raid and party unit tokens in a fast O(1) hash table that updates on roster changes. * **Performance Fix - Range Cache GC Leak** - Fixed a continuous memory leak in the range checker caused by string concatenation (`unit .. "_" .. range`) running every frame. Range states are now stored in a nested numeric table cache. +* **Performance Fix - Talent Rank Scan** - Fixed severe CPU stutter when gaining or losing auras that affect stats. Previously, inventory updates forced a full equipment and spell recalculation which linearly scanned the entire talent tree multiple times per rank. Talent ranks are now cached natively. * **Integrations Bug Fix** - Removed stray translation text from `HealBot_Integrations.lua` that caused Lua syntax errors on load. **v1.7.3**