Skip to content

Commit

Permalink
perf: suspend when tasks are active
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 30, 2024
1 parent c7ed87f commit 2f4ac03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 18 additions & 1 deletion lua/lazy/async.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion lua/lazy/manage/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ function Runner:_start()
end
continue(true)
end
coroutine.yield()
if active > 0 then
self._running:suspend()
end
end
end

Expand Down

0 comments on commit 2f4ac03

Please sign in to comment.