Skip to content

Commit 27b7a00

Browse files
committed
perf: defer registered plugins cache update to UIEnter
Using vim.schedule alone still impacted startup time. Deferring update_registered_plugins_cache to UIEnter (like VeryLazy) ensures the cache is populated after the UI loads, improving perceived startup performance. Updated test helper flush_pending() to trigger UIEnter so tests properly simulate the deferred behavior.
1 parent e52848d commit 27b7a00

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

lua/zpack/init.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,12 @@ M.setup = function(opts)
154154

155155
local commands = require('zpack.commands')
156156
commands.setup(config.cmd_prefix)
157-
vim.schedule(commands.update_registered_plugins_cache)
157+
vim.api.nvim_create_autocmd("UIEnter", {
158+
callback = function()
159+
vim.schedule(commands.update_registered_plugins_cache)
160+
end,
161+
once = true,
162+
})
158163
end
159164

160165
---@deprecated Use setup({ spec = { ... } }) instead

tests/helpers.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ function M.wait_for_condition(condition, timeout_ms, interval_ms)
275275
end
276276

277277
function M.flush_pending()
278+
-- Trigger UIEnter to fire autocmds that defer work until after UI loads
279+
vim.api.nvim_exec_autocmds("UIEnter", {})
278280
-- Process all pending vim.schedule callbacks by waiting with a condition that
279281
-- never returns true. 50ms is sufficient for most deferred operations while
280282
-- keeping tests fast. The condition returns false to ensure we always wait

tests/lazy_event_test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ return function()
118118
defaults = { confirm = false },
119119
})
120120

121-
helpers.flush_pending()
122121
local autocmds = vim.api.nvim_get_autocmds({ group = state.lazy_group })
123122
helpers.assert_not_nil(
124123
helpers.find_autocmd(autocmds, 'UIEnter'),
125124
"VeryLazy should create UIEnter autocmd"
126125
)
127126

127+
helpers.flush_pending()
128128
helpers.cleanup_test_env()
129129
end)
130130

0 commit comments

Comments
 (0)