I'm using the code snippet as shown below to "lazyload" some of my plugins for Neovim. I wrote the same function, once in LUA and once in vimscript. I would like to use the LUA implementation to try and get away from vimscript; however, in my tesing the lua version is significantly slower than the vimscript version.
It is worth noting, yes, the the autocommands are technically not exactly the same as the vimscript version is calling defer_fn
to wait an additional millisecond before running the autocommand in this case. Regardless of this, both versions are using the same event VimEnter
, so I do not understand why the lua version is so much slower.
lua version:
vim.api.nvim_create_autocmd({"VimEnter"}, {
pattern = {"*"},
callback = load_plugins,
})
Average Time of Nvim Startup: 33 ms
Vimscript version:
vim.cmd [[
augroup user_cmds
autocmd!
autocmd VimEnter * lua vim.defer_fn(load_plugins, 1)
augroup END
]]
Average Time of Nvim Startup: 23 ms