perf(notifier): skip processing queue when free space is smaller than min height

This commit is contained in:
Folke Lemaitre 2024-11-08 00:10:36 +01:00
parent 12077bcf65
commit 08190a5458
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -540,27 +540,34 @@ function N:layout()
end end
end end
local shown = 0 local free = #vim.tbl_filter(function(v)
local max_visible = vim.o.lines * (self.opts.height.min + 2) return v
end, rows)
for _, notif in ipairs(assert(self.sorted)) do for _, notif in ipairs(assert(self.sorted)) do
local skip = shown >= max_visible local skip = free < (self.opts.height.min + 2)
local changed = false
if not skip then if not skip then
if not notif.win or notif.dirty or not notif.win:buf_valid() or type(notif.opts) == "function" then if not notif.win or notif.dirty or not notif.win:buf_valid() or type(notif.opts) == "function" then
notif.dirty = false notif.dirty = false
self:render(notif) self:render(notif)
---@diagnostic disable-next-line: assign-type-mismatch ---@diagnostic disable-next-line: assign-type-mismatch
notif.layout = vim.tbl_deep_extend("force", notif.layout or {}, { size = notif.win:size() }) notif.layout = vim.tbl_deep_extend("force", notif.layout or {}, { size = notif.win:size() })
changed = true
end end
local old_top = notif.layout.top
notif.layout.top = find(notif.layout.size.height, notif.layout.top) notif.layout.top = find(notif.layout.size.height, notif.layout.top)
changed = changed or old_top ~= notif.layout.top
end end
if not skip and notif.layout.top then if not skip and notif.layout.top then
shown = shown + 1 free = free - notif.layout.size.height
mark(notif.layout.top, notif.layout.size.height, false) mark(notif.layout.top, notif.layout.size.height, false)
notif.win.opts.row = notif.layout.top - 1 if changed then
notif.win.opts.col = vim.o.columns - notif.layout.size.width - self.opts.margin.right notif.win.opts.row = notif.layout.top - 1
notif.shown = notif.shown or ts() notif.win.opts.col = vim.o.columns - notif.layout.size.width - self.opts.margin.right
notif.win:show() notif.shown = notif.shown or ts()
notif.win:update() notif.win:show()
notif.win:update()
end
elseif notif.win then elseif notif.win then
notif.shown = nil notif.shown = nil
notif.win:hide() notif.win:hide()