vendethiel / GladiusEx

14 stars 20 forks source link

replace `wipe` calls #4

Closed vendethiel closed 6 years ago

vendethiel commented 6 years ago

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

slaren commented 6 years ago

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.

vendethiel commented 6 years ago

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