-
-
Notifications
You must be signed in to change notification settings - Fork 294
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] Lazy loading #421
Comments
A (relatively) easy way to do this, compared to This way, we can Second, probably easier, option - the vast majority of the plugins we support are lua-based plugins. The majority of the loading time there is spent on the Either way, I will be looking into how lazy-loading in neovim has been traditionally done, since I don't have much experience with it, and will try to come up with some way it could work. |
Also, another feature |
Some references:
|
Great ! Thanks and good luck :) |
Yesterday I found out about nixvim. I'm already using home-manager. I'm not sure I would migrate though. I do some customization for neovim loading to greatly improve startup time and I'm not sure I can insert nixvim in that process. But the project looks interesting. Still I wanted to comment about lazy loading. What I think is most important for startup time are:
So even not doing any lazy-loading I have a decent startup time. Without all these optimizations |
Thank you so much @stasjok for this great insight of your config ! |
I'm not using nixvim either because I need the lazy-loading but I'd like to chip in an idea. If you're willing to outsource some of the code, I'd suggest using lazy.nvim seeing as it's pretty good at lazy-loading + it would reduce the maintenance burden for developing nixvim. Its variety of options and features could come in handy. It even has async execution and automatic caching and bytecode compilation of Lua modules for improved performance. You could provide options to configure it in nix and then translate that to lua like you do with the rest of nixvim. Lazy's I've written some examples below to illustrate the idea. {
plugins.lazy = {
enable = true;
# install any plugin available in the nix repos
nix = {
# this installs vimPlugins.neorg
neorg = {
build = ":Neorg sync-parsers";
dependencies = [
# these are all from the nix repos too
# they load when Neorg loads
plenary-nvim
nvim-treesitter
neorg-telescope = {
dependencies = [ telescope-nvim ];
config = ''
-- this is lua code
-- it does not get loaded until neorg-telescope is loaded
vim.wo.foldlevel = 99
'';
};
];
cmd = "Neorg";
ft = "norg";
keys = "<c-t>n";
# sometimes we like to keep the config in a different file
# so source it from elsewhere
config = import ./neorg.nix;
};
nvim-colorizer-lua = {
cmd = "ColorizerToggle"; # only load colorizer when I use :ColorizerToggle
config = ''
-- more lua code
vim.g.termguicolors = true,
require("colorizer").setup()
'';
};
};
# obscure plugin that isn't available in the nix repos
git."Vonr/align.nvim" = {
branch = "v2";
# only load align.nvim when the user presses <leader>a in visual mode
keys = [
{ "<leader>a"; mode = "v"; };
];
config = ''
vim.keymap.set(
'v',
'<leader>a',
function()
require'align'.align_to_string({
preview = true,
})
end,
{ noremap = true, silent = true }
)
'';
};
};
} This would install -- add lazy.nvim to the runtime path
vim.opt.rtp:prepend("/nix/store/rjkwbzdmdfp9gfrvi0rch5g5illqwbgf-vimplugin-lazy.nvim-2023-08-26")
require("lazy").setup({
{
name = "neorg",
dir = "/nix/store/iwxg2w4blbphyk7yvf7drqkmf8qfyv4x-vimplugin-neorg-2023-09-15",
build = ":Neorg sync-parsers",
dependencies = {
{ name = "plenary.nvim", dir = "/nix/store/4f17ss3v7lv580hmca8pc2q3zn33lqk4-lua5.1-plenary.nvim-2023-09-12" },
{ name = "nvim-treesitter", dir = "/nix/store/vp0lhrdzvknz7rb8pc6ndvv28cgsfy14-vimplugin-nvim-treesitter-2023-09-16" },
{
name = "telescope.nvim",
dir = "/nix/store/1ldgn56d6sgmk42n6dna3b91w3si3sn7-lua5.1-telescope.nvim-2023-09-16",
dependencies = { name = "neorg-telescope", dir = "/nix/store/rvg763iaqbx3czb52ghrsxhidvqqgwbk-vimplugin-neorg-telescope-2023-08-06" },
config = function()
-- this is lua code
-- it does not get loaded until neorg-telescope is loaded
vim.wo.foldlevel = 99
end,
},
},
cmd = "Neorg",
ft = "norg",
keys = "<c-t>n",
config = function()
require("path.to.neorg.config")
end,
},
{
name = "nvim-colorizer.lua",
dir = "/nix/store/03k72h7x4m543z7vrqjwbvqjx6j789qg-vimplugin-nvim-colorizer.lua-2023-02-27",
cmd = "ColorizerToggle",
config = function()
-- more lua code
vim.g.termguicolors = true,
require("colorizer").setup()
end,
},
{
"Vonr/align.nvim",
branch = "v2",
keys = {{ "<leader>a", mode = "v" }},
config = function()
vim.keymap.set(
'v',
'<leader>a',
function()
require'align'.align_to_string({
preview = true,
})
end,
{ noremap = true, silent = true }
)
end,
},
}) Note that you shouldn't try to lazy-load lazy.nvim or the colourscheme. These should be loaded on startup. Cut me some slack if any of the nix or lua code above has mistakes. I'm pretty new to both languages and have so far not used them for anything besides configuring NixOS/home-manager and Neovim. |
Oh btw, I came across another project called nixneovim, which seems to have pretty much the same goal as you. I don't believe they do lazy-loading but maybe some of their stuff would interest you, such as their auto-updated plugins repo. |
Thanks for the link @koalagang ! |
you are right, no backporting. It's not critical software + we usually dont run the tests (when there are tests !) so backporting would be tricky. Plus the tooling is not great.
I am glad to learn about this, I've wanted to see this (not use it though) so that users can contribute to the nixpkgs plugin updater. Haven't seen much contribution from the usual contributors sadly. |
@teto if you are interested I have a different approach for my plugin management: |
plugins repo uses their own updater so I better understand why they dont contribute to upstream. Would be interesting to compare the features of both and see if we can merge both approaches. @traxys > I've seen that approach before. it's LGTM and to some extent, I wish we would leverage nix flake archive in the upstream updates like it's done for treesitter grammars already. Configuring neovim via nix is a bit tedious for most things so I use it only when the trade off is positive (plugins with complex dependencies and that) so I maintain a hybrid config with lazy to install hte other half of my plugins. |
@GaetanLepage I definitely agree that upstreaming plugins is ideal but surely users should have access to a way of installing plugins that haven't been upstreamed? If one wants a plugin immediately and said plugin is not in the nix repos then what would one do? Of course, you should then ask for this to be added and upstreamed so that all users can benefit but I don't think users should be forced to do this, especially considering that, like you rightfully said, those not on the unstable channel would have to wait for a whole new release to install those plugins. There should be some way of grabbing it straight from a git repo just like traditional vim plugin managers do. I think perhaps Anyway, this might be diverging slightly from the topic of how Nixvim is going to handle lazy-loading. |
If you're okay with having flakes as a requirement, you can use But I do like the idea of generating |
@musjj Haha I just discovered like 15 minutes after posting my comment that this is what flakes do 😅 But yeah, again I like the idea of using lazy.nvim. It should possible be to do it with home-manager rather than with nixvim, which I am considering. If, instead of using So for example: { pkgs, ... }:
{
programs.neovim.extraLuaConfig = ''
-- this is lua code
vim.opt.rtp:prepend(${pkgs.vimPlugins.lazy-nvim})
require("lazy").setup({
{
name = "nvim-colorizer.lua",
dir = "${pkgs.nvim-colorizer-lua}",
cmd = "ColorizerToggle",
config = function()
vim.g.termguicolors = true,
require("colorizer").setup()
end,
},
})
'';
} Note that The only difference between this and my suggestion earlier was basically that nixvim could do this but allowing the user to write it directly in nix rather than embedding lua code into a nix file. P.s. I've never done this nor have I seen it being done. It's just something that, logically, I think would work. |
|
Are plugin versions locked with |
lazy.nvim has a json lockfile that stores the branch and commit for each dependency that it pulls via git. I'm not sure how it handles local directory dependencies. |
As @bmanuel rightfully said, if pulling via git then it will use its own lockfile implementation ( |
@koalagang I agree, the goal is not to force the user to upstream packages.
|
This sounds like we could encapsulate the entire |
A lazy.nvim module sounds great, although I still think the original proposal of doing as much as possible in nix (at build time) is the ideal. That said, perfection is the enemy of good... |
Just popping back in here to add a datapoint for lazy.nvim: We used to have a module for a popular nvim package manager (packer? I forget...). It's what was used before to install packages outside of Nix, but had some issues. Either way, I'm not particularly opposed to having I don't really see a reason not to have both. |
Indeed! Otherwise, IIRC
We could trigger |
Recently we introduced new helpers to create plugin modules ( |
So... it looks like to use the new lazy module we ("we" being me, someone just using nixvim who doesn't really know what's going on) have to re-do how we setup plugins so they can be loaded with lazy? Is that something I should be doing, or is it going to change soon and we're in kindof an interim state at the moment? |
Currently, yes.
If you want to try out lazy loading now, yes. If you don't like re-doing your config, no.
The plan is to add a |
I had an idea what if lazy.nvim had an option that affects all plugins to lazy load the option could be |
This library could be useful: https://github.com/nvim-neorocks/lz.n |
I was just thinking this actually; if I could just enable it then set lazy loading options based on filetype or something and then just enable |
Yeah I agree with this, but what about others like rock.nvim you would have to do a warning or panic when using others. |
Just came across this independently and came here to suggest this haha. Do you think maybe you could create a module for this like was done for lazy.nvim and then that would essentially be nixvim's lazy-loading feature complete? The reason lazy.nvim was added was purely for it's lazy-loading ability (or at least that's the only reason I suggested it) so lz.n would essentially do this job but without the added code for managing plugin installation (incl. Btw, as an alternative to creating an independent module for lz.n, you could add Unless I'm missing something (which is entirely possible 😅), this should solve the problem of lazy-loading for nixvim. |
We now have support for |
Any progress on this feature? |
Unfortunately, we have not made a ton of progress on this. Things have been very busy lately. Basically, implementing lazy loading will boil down to three steps:
This will surely takes some time.
Anyway, thank you all for your patience. Lazy loading is the number 1 big feature on our TODO list ;) |
I did create #2577 as a quick POC on how a simple first step implementation could be done. @MattSturgeon and I talked about it a bit on matrix and figure we could roll out the work in steps. The first PR will be that one with the ability for people to manually manage their lazy loading, then we will work on continuing the implementation of making nixvim ease the configuration. |
I am on vacation as of now, so I think I could help with some PRs to do so. |
Is there a seperate branch to contribute to? As this will change the codebase and will trigger a big build in nixvim builder which is the nix-community infra. |
Apart from @khaneliman 's PoC PR, no, there is no branch yet. |
✅ Lazy loading support (beta) 🦥🚀After a very long time, we are finally releasing lazy loading support in Nixvim !
|
Initial implementation done in #2602. |
Awesome work guys! |
Considering how requested this functionality is, it would be great to open a tracking issue for the following tasks in order to keep interested users up-to-date:
Please write a message in this thread with a link to the new tracking issue in order for everyone to be notified, allowing them to subscribe to the new thread. |
So excited for this! 🥳 |
Good idea ! Opened #2632. |
-->Summary: https://notes.glepage.com/rA_fyfKESvC9OxGGNHOYXw#Lazy-Loading <--
Currently, nixvim relies on the neovim built-in way of loading plugins.
This is implemented by nixpkgs neovim's module. It has the advantage of existing and leveraging the collection of plugins packaged in nixpkgs.
With that said, the very popular
lazy.nvim
plugin manager proposes a more performant way of loading plugins.Imitating their lazy loading process could be a very valuable addition to nixvim.
I would guess that this feature should be optional so that conventional loading would stay the default.
As of today, no-one has started to work on this issue.
Feel free to go and make a PR, even if the work is in draft-stage. I will personally be glad to review and discuss a proposed implementation.
The text was updated successfully, but these errors were encountered: