Aux no longer consumes resources when not in use

Aux would perform unnecessary tasks every frame even when not in use. This has been solved by only running those tasks when Aux is actually doing things.
This commit is contained in:
OldManAlpha
2025-09-19 12:35:36 -07:00
parent 2475043039
commit 4775b3ab7f
2 changed files with 29 additions and 14 deletions
+9 -2
View File
@@ -2,7 +2,7 @@ module 'aux'
local T = require 'T' local T = require 'T'
local event_frame = CreateFrame'Frame' local event_frame = CreateFrame('Frame', 'AuxThreadingFrame')
local listeners, threads = T.acquire(), T.acquire() local listeners, threads = T.acquire(), T.acquire()
@@ -10,7 +10,6 @@ local thread_id
function M.thread_id() return thread_id end function M.thread_id() return thread_id end
function handle.LOAD() function handle.LOAD()
event_frame:SetScript('OnUpdate', UPDATE)
event_frame:SetScript('OnEvent', EVENT) event_frame:SetScript('OnEvent', EVENT)
end end
@@ -39,6 +38,11 @@ do
for id, thread in threads do for id, thread in threads do
if thread.killed or not thread.k then if thread.killed or not thread.k then
threads[id] = nil threads[id] = nil
local hasLiveThread = false
for _ in pairs(threads) do hasLiveThread = true break end
if not hasLiveThread then -- Disable threading task so it doesn't consume resources doing nothing
event_frame:SetScript('OnUpdate', nil)
end
else else
local k = thread.k local k = thread.k
thread.k = nil thread.k = nil
@@ -100,6 +104,9 @@ do
arg.f = tremove(arg, 1) arg.f = tremove(arg, 1)
local thread_id = unique_id() local thread_id = unique_id()
threads[thread_id] = T.map('k', setmetatable(arg, mt)) threads[thread_id] = T.map('k', setmetatable(arg, mt))
if event_frame:GetScript("OnUpdate") == nil then -- Spin up threading if it was turned off
event_frame:SetScript('OnUpdate', UPDATE)
end
return thread_id return thread_id
end end
+20 -12
View File
@@ -15,13 +15,6 @@ function wipe(t)
end end
M.wipe = wipe M.wipe = wipe
CreateFrame'Frame':SetScript('OnUpdate', function()
for t in auto_release do
release(t)
end
wipe(auto_release)
end)
function acquire() function acquire()
if pool_size > 0 then if pool_size > 0 then
pool_size = pool_size - 1 pool_size = pool_size - 1
@@ -36,6 +29,19 @@ function acquire()
end end
M.acquire = acquire M.acquire = acquire
local f = CreateFrame('Frame', 'AuxGCFrame')
local function AuxGCFrame_OnUpdate()
for t in auto_release do
release(t)
end
wipe(auto_release)
this:SetScript("OnUpdate", nil) -- Remove the script, it will be set back if anything is added to auto_release
end
local function autoRelease(t)
auto_release[t] = true
f:SetScript("OnUpdate", AuxGCFrame_OnUpdate)
end
function release(t) function release(t)
wipe(t) wipe(t)
auto_release[t] = nil auto_release[t] = nil
@@ -51,7 +57,7 @@ M.release = release
do do
local function f(_, v) local function f(_, v)
if v then if v then
auto_release[v] = true autoRelease(v)
return v return v
end end
end end
@@ -85,7 +91,7 @@ do
local MAXPARAMS = 100 local MAXPARAMS = 100
local code = [[ local code = [[
local f, setn, acquire, auto_release = f, setn, acquire, auto_release local f, setn, acquire, autoRelease = f, setn, acquire, autoRelease
return function( return function(
]] ]]
for i = 1, MAXPARAMS - 1 do for i = 1, MAXPARAMS - 1 do
@@ -103,7 +109,7 @@ do
code = code .. [[ code = code .. [[
until true until true
local t = acquire() local t = acquire()
auto_release[t] = true autoRelease(t)
setn(t, n) setn(t, n)
repeat repeat
]] ]]
@@ -116,9 +122,11 @@ do
end end
]] ]]
local chunk = loadstring(code)
local chunkEnv = {setn=setn, acquire=acquire, auto_release=auto_release, autoRelease=autoRelease}
setfenv(chunk, chunkEnv)
function vararg(f) function vararg(f)
local chunk = loadstring(code) chunkEnv.f = f
setfenv(chunk, {f=f, setn=setn, acquire=acquire, auto_release=auto_release})
return chunk() return chunk()
end end
M.vararg = setmetatable({}, { M.vararg = setmetatable({}, {