fix: improve performance and safety with null checks and talent rank caching

This commit is contained in:
Bluewhale1337
2026-10-04 17:54:00 +02:00
parent 526a4f1b9b
commit 2a0d607bcd
5 changed files with 23 additions and 22 deletions
+1
View File
@@ -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
+1 -1
View File
@@ -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
+2
View File
@@ -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
+18 -21
View File
@@ -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")
+1
View File
@@ -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**