perf: automatically suspend the scheduler when all threads are waiting

This commit is contained in:
Folke Lemaitre 2024-06-29 22:44:51 +02:00
commit 021de31682
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 78 additions and 47 deletions

View file

@ -78,6 +78,7 @@ function Runner:_start()
---@type number?
local wait_step = nil
---@async
---@param resume? boolean
local function continue(resume)
active = 0
@ -114,22 +115,30 @@ function Runner:_start()
end
local s = state[name]
local plugin = self:plugin(name)
if s.step == #self._pipeline then
-- done
s.task = nil
plugin._.working = false
elseif s.step < #self._pipeline then
-- next
s.step = s.step + 1
local step = self._pipeline[s.step]
if step.task == "wait" then
while s.step <= #self._pipeline do
if s.step == #self._pipeline then
-- done
s.task = nil
plugin._.working = false
waiting = waiting + 1
wait_step = s.step
else
s.task = self:queue(plugin, step)
plugin._.working = true
active = active + 1
break
elseif s.step < #self._pipeline then
-- next
s.step = s.step + 1
local step = self._pipeline[s.step]
if step.task == "wait" then
plugin._.working = false
waiting = waiting + 1
wait_step = s.step
break
else
s.task = self:queue(plugin, step)
plugin._.working = true
if s.task then
active = active + 1
s.task:wake(false)
break
end
end
end
end
end

View file

@ -21,6 +21,7 @@ M.log = {
---@async
---@param opts {args?: string[], updated?:boolean, check?:boolean}
run = function(self, opts)
-- self:spawn({ "sleep", "5" })
local args = {
"log",
"--pretty=format:%h %s (%cr)",