perf: suspend when tasks are active

This commit is contained in:
Folke Lemaitre 2024-06-30 09:13:04 +02:00
parent c7ed87f9ca
commit 2f4ac035bc
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 21 additions and 2 deletions

View File

@ -152,12 +152,29 @@ function M.step()
table.insert(state._suspended and M._suspended or M._active, state)
end
-- print("step", #M._active, #M._suspended)
-- M.debug()
if #M._active == 0 then
return M._executor:stop()
end
end
function M.debug()
local lines = {
"- active: " .. #M._active,
"- suspended: " .. #M._suspended,
}
for _, async in ipairs(M._active) do
local info = debug.getinfo(async._fn)
local file = vim.fn.fnamemodify(info.short_src:sub(1), ":~:.")
table.insert(lines, ("%s:%d"):format(file, info.linedefined))
if #lines > 10 then
break
end
end
local msg = table.concat(lines, "\n")
M._notif = vim.notify(msg, nil, { replace = M._notif })
end
---@param async Async
function M.add(async)
table.insert(M._active, async)

View File

@ -153,7 +153,9 @@ function Runner:_start()
end
continue(true)
end
coroutine.yield()
if active > 0 then
self._running:suspend()
end
end
end