-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: load handlers lazily #1442
Labels
enhancement
New feature or request
Comments
I think |
You are right. User command can be called before |
The |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: