You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
When too many lazy handlers are added, lazy.nvim will take too long to enable all of them.
I had hundreds of keys handlers and that slow startup time a lot.
But these handlers are not possible to trigger before some specific events, and it's a waste of time for starting these handlers in the startup.
e.g: keys handler is always after "SafeState", because user can't type any command before that. cmd handler is always after "CmdlineChange" since user needs to type one character for run a command or do a completion (or "CmdlineEnter" if user uses other way to do that). ft handler is always after "BufEnter" ("BufNewFile" or "BufReadPost" when starting Neovim with a file parameter).
And most of event handlers are after "SafeState" too.
My solution is a bit extreme, ft and event part may not very stable, but the keys and cmd handler is very stable for SafeState and CmdlineEnter event. Simply loading these two events lazily can reduce most of the load time.
Additional context
I installed 109 plugins in total, here's how this optimization improves startup time:
before
after
Note the handlers is taking 18.53ms before, and now it only takes 1.44ms, it's about 10 time faster (the improvement base on how many handlers you had in total)
The text was updated successfully, but these errors were encountered:
I think cmd should not be loaded on CmdlineEnter or CmdlineChanged.
Because the commands may be called from cmd-mappings. It does not call command line events.
You are right. User command can be called before CmdlineEnter, but I think most User command will be called after CmdlineEnter, There could be a way to balance all this.
Did you check the docs?
Is your feature request related to a problem? Please describe.
When too many lazy handlers are added, lazy.nvim will take too long to enable all of them.
I had hundreds of keys handlers and that slow startup time a lot.
But these handlers are not possible to trigger before some specific events, and it's a waste of time for starting these handlers in the startup.
e.g:
keys
handler is always after "SafeState", because user can't type any command before that.cmd
handler is always after "CmdlineChange" since user needs to type one character for run a command or do a completion (or "CmdlineEnter" if user uses other way to do that).ft
handler is always after "BufEnter" ("BufNewFile" or "BufReadPost" when starting Neovim with a file parameter).And most of
event handlers
are after "SafeState" too.lazy.nvim/lua/lazy/core/handler/init.lua
Lines 100 to 109 in d397434
lazy.nvim/lua/lazy/core/handler/init.lua
Lines 47 to 57 in d397434
Describe the solution you'd like
I write a demo outside the lazy.nvim in my configuration.
You can try this code before lazy.setup(), it will override the original handler.
Describe alternatives you've considered
My solution is a bit extreme, ft and event part may not very stable, but the keys and cmd handler is very stable for
SafeState
andCmdlineEnter
event. Simply loading these two events lazily can reduce most of the load time.Additional context
I installed 109 plugins in total, here's how this optimization improves startup time:
before
after
Note the handlers is taking 18.53ms before, and now it only takes 1.44ms, it's about 10 time faster (the improvement base on how many handlers you had in total)
The text was updated successfully, but these errors were encountered: