Closed stasjok closed 1 year ago
The compiled cache is twice as fast than normal highlight for me
I will try to reproduce your issue on a nixos docker
@stasjok Can you run vim.cmd.colorscheme "catppuccin"
instead? It is currently combined so I am unsure which part is slow
I traced down a slowness to
https://github.com/catppuccin/nvim/blob/8d4b9ed1f9cb5a575a1fa25c506409416d347241/lua/catppuccin/lib/compiler.lua#L26
Without extra vim.o.background = "dark"
(which is default in neovim) the speed is normal:
028.927 000.113 000.113: require('catppuccin')
029.654 000.868 000.755: sourcing /home/stas/.config/nvim/plugin/colorscheme.lua
Also notice that there is no extra sourcing /nix/store/7xzxpsa1d366501v259ywwghxj329bkj-vim-pack-dir/pack/myNeovimPackages/start/catppuccin-nvim/colors/catppuccin.vim
line. Probably changing background triggers loading of colorscheme again, and maybe some autocommands from plugins. So my 7 ms maybe from plugins triggered by colorscheme change.
So regarding "a compiled version is slow for me" I guess I was wrong.
But the stale cache for nix plugin stands. The only way I know to determine if plugin is updated is compare path. Hash part here /nix/store/7xzxpsa1d366501v259ywwghxj329bkj-vim-pack-dir
is unique for every version of plugin (new versions are placed in new directories in store).
I unfortunately can't run your nix config
❯ nix registry add mypkgs github:stasjok/dotfiles
error: experimental Nix feature 'nix-command' is disabled; use '--extra-experimental-features nix-command' to override
Even though I have added the experiement flag to .config/nix.conf
vim.cmd.colorscheme "catppuccin"
It doesn't make any difference. If I add vim.o.background = "dark"
to my Test case 2, than it's 10 ms.
Without extra vim.o.background = "dark" (which is default in neovim) the speed is normal:
I literally have a lock to avoid colorscheme getting loaded twice https://github.com/catppuccin/nvim/blob/main/lua/catppuccin/init.lua#L75
I unfortunately can't run your nix config
❯ nix registry add mypkgs github:stasjok/dotfiles error: experimental Nix feature 'nix-command' is disabled; use '--extra-experimental-features nix-command' to override
Even though I have added the experiement flag to .config/nix.conf
I guess I was wrong in README. Home config is $XDG_CONFIG_HOME/nix/nix.conf
. There is missing nix
directory. I have config in /etc/. Also you can add command line option like it suggests.
But I don't think it worth spending time trying my config. I also tried with -u NONE
and it's also fast. So I think it is plugins or their autocommands triggered by colorsheme change.
cc @edeneast
I heard you also use nix, any idea on this? (The no .git/
folder issue)
I would suggest that if there is no git
stat info then getting the fstat of a file in catppuccin ./lua/catppuccin/init.lua
for example. Since every change is a new entry in the nix store it will also have different fstat values.
I do use nixos for my linux installs and nix and home-manger for my other non-linux systems. My nvim config changes so constantly that I just symlink my nvim config. I use packer with this pr to give me lockfile support so at least I have a lockfile for the plugins.
But the original poster's directory stat is Jan 1 1970
I am a lil confused
Ahhh I just checked my nix-store and you are right all the files are at the beginning of epoch.
Thinking about the reason that the git stat is there is to check if the plugin has been changed / updated. How about precomputing a hash of the contents of the repo.
How about instead of getting the fstat of the .git/ORIG_HEAD
file there is a precomputed hash of all the contents of for example:
fd . -t f lua autoload plugin colors | sha1sum | awk '{print $1}'
This could be part of a precommit hook, or a workflow that would create a this file when there is a new commit into main.
Just an idea.
But the original poster's directory stat is
Jan 1 1970
I am a lil confused
All files in nix store have timestamp 1 second since epoch. It's by design. You don't have to fix it (I mean a special case like Nix), but if you want to, I think you can rely only on a combination of file path + mtime (e.g. some hash on both).
Regarding startup time, moving colorscheme loading to init.lua
(essentially before any plugin) fixed speed.
Is your feature request related to a problem? Please describe.
A compiled version is slow for me (around 7 ms). Regular highlights is faster (around 3 ms with impatient.nvim, without impatient it may be slow, I don't know).
Test case 1 (default)
plugin/colorscheme.lua
:startuptime:
Notice that summary time for
colorscheme.lua
is 6,9 ms. Basically almost all that time is spend loading compiled file.Test case 2 (no compiler)
plugin/colorscheme.lua
:startuptime:
Notice that summary time for
colorscheme.lua
is 2,9 ms. Maybe it can even be optimized further.I think that at least in my case luajit loop is faster than multiple commands in a compiled file.
Second problem I have is that I'm using Nix. A code for determining if the plugin is updated:
https://github.com/catppuccin/nvim/blob/8d4b9ed1f9cb5a575a1fa25c506409416d347241/lua/catppuccin/init.lua#L123
won't work, because plugin directory in nix doesn't have
.git
directory and all files have the same date:So it will result in a stale cache after plugin directory is updated.
Describe the solution you'd like An ability to disable auto compilation, or an optimization of compiled code.
Describe alternatives you've considered Do everything manually like in Test case 2, but it can be prone to errors after updates because it's not an official API.