replace `wipe` calls
vendethiel opened this issue ยท 2 comments
@slaren asking you here.
I'm trying to optimize a bit the addon, and I stumbled upon this in modules/cooldowns.lua
local spell_list = {}
local unit_sorted_spells = {}
local function GetCooldownList(unit, group)
local db = Cooldowns:GetGroupDB(unit, group)
local specID, class, race = GetUnitInfo(unit)
-- generate list of valid cooldowns for this unit
wipe(spell_list)
What's the point of wiping the spell list instead of just using a local table?
Does it save some allocations maybe, because the table's backing array (in C parlance) is not reset?
Yes, that's the idea, wipe should be faster than creating a new table because it reuses the memory that was already allocated, and you want to avoid allocations in functions called frequently to prevent excessive garbage collection.