performance improvements

This commit is contained in:
Manuel Simon Hirsig
2016-11-07 03:24:02 +01:00
parent ef1a82675d
commit 55de23654b
19 changed files with 160 additions and 151 deletions
+22 -9
View File
@@ -2,23 +2,27 @@ library 'green_t'
local next, getn, setn, tremove, type, setmetatable = next, getn, table.setn, tremove, type, setmetatable
local wipe, acquire, release, auto_release
local wipe, acquire, release, auto_release, dep_release
do
local pool, pool_size, overflow_pool, auto_release_queue = {}, 0, setmetatable({}, {__mode='k'}), {}
local pool, pool_size, overflow_pool, is_auto_release, is_dep_release = {}, 0, setmetatable({}, {__mode='k'}), {}, setmetatable({}, {__mode='k'})
function wipe(t)
setmetatable(t, nil)
for k in t do t[k] = nil end
for k, v in t do
if is_dep_release[v] then release(v) end
t[k] = nil
end
t.reset, t.reset = nil, 1
setn(t, 0)
end
M.wipe = wipe
CreateFrame'Frame':SetScript('OnUpdate', function()
for t in auto_release_queue do release(t) end
wipe(auto_release_queue)
for t in is_auto_release do release(t) end
wipe(is_auto_release)
end)
local kek = 0
function acquire()
if pool_size > 0 then
pool_size = pool_size - 1
@@ -29,13 +33,16 @@ do
overflow_pool[t] = nil
return t
end
kek = kek + 1
if mod(kek, 100) == 0 then p(kek, debugstack()) end
return {}
end
M.acquire = acquire
function release(t)
wipe(t)
auto_release_queue[t] = nil
is_auto_release[t] = nil
is_dep_release[t] = nil
if pool_size < 50 then
pool_size = pool_size + 1
pool[pool_size] = t
@@ -47,9 +54,15 @@ do
function auto_release(v, enable)
if type(v) ~= 'table' then return end
auto_release_queue[v] = enable and true or nil
is_auto_release[v] = enable and true or nil
end
M.auto_release = auto_release
function dep_release(v, enable)
if type(v) ~= 'table' then return end
is_dep_release[v] = enable and true or nil
end
M.dep_release = dep_release
end
M.get_t = acquire
@@ -65,10 +78,10 @@ M.temp = setmetatable({}, {
__newindex = nop,
__sub = function(_, v) auto_release(v, true); return v end,
})
M.static = setmetatable({}, {
M.weak = setmetatable({}, {
__metatable = false,
__newindex = nop,
__sub = function(_, v) auto_release(v, false); return v end,
__sub = function(_, v) dep_release(v, true); return v end,
})
do