catppuccin.nvim now startup in 1ms
3 months ago I implementedprecompiled cache intocatppuccin/nvim
Why? Catppuccin is a highly customizable and configurable colorscheme. This does however come at the cost of complexity and execution time. We pre-compute the results of your configuration and store the results in a compiled lua file then use it to set highlights.
However it wasn't enabled by default like nightfox.nvim because you needed to manually recompile after changing config and install/update hook doesn't work very well (vim-plug for example). Last week I had an idea of auto compile only when:
User configuration file date changed
vim.fn.getftime(debug.getinfo(2).source:sub(2))(Extra check for compile criteria only if user doesn't have the same setup table content)User updated the plugin
vim.fn.getftime(".git/ORIG_HEAD")
Implementation detailscan be found here.
Here is a table to compare its performance to others (With the default config). Note that I used default config which is why the startuptime seems insignificant)
| Colorscheme | Time (ms) |
|---|---|
| catppuccin/nvim | 1.387383 |
| nightfox.nvim | 2.732962 |
| material.nvim | 2.333946 |
| tokyonight.nvim | 5.374398 |
| onedark.nvim | 3.384723 |
| everblush.nvim | 1.254077 |
| kanagawa.nvim | 2.760432 |
Do note that plugins usedvim.loop.new_async (material.nvim) have much higher startuptime than shown in the table above. I will letTJ explain why this isn't actually faster
Note that this benchmark doesn't speak for itself (Hand benchmark 20 times each colorscheme and take the fastest result) nor is it biased toward catppuccin (If you have a better benchmark script please let me know) as the best time I got is < 1ms:
014.735 000.087 000.087: require('catppuccin')015.595 000.524 000.524: sourcing /home/nullchilly/.local/share/nvim/site/pack/packer/start/catppuccin/colors/catppuccin.lua015.618 000.999 000.387: require('config.catppuccin')Code used to benchmark:
local theme = "kanagawa"local now = vim.loop.hrtime local start = now()require(theme).setup{} vim.api.nvim_command("colorscheme " .. theme)print((now() - start) / 1000000)