GladiusEx

GladiusEx

4M Downloads

replace `wipe` calls

vendethiel opened this issue ยท 2 comments

commented

@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?

commented

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.

commented

Okay, that's about what I was thinking. Just wanted to make sure, ty for the fast answer.