wbthomason / packer.nvim

A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config
MIT License
7.86k stars 265 forks source link

Using config key causes startup slowdown #69

Closed smolck closed 3 years ago

smolck commented 3 years ago

If I move certain require statements and Lua configuration code to use the config key instead of be run in a Lua file, my startup time is an extra ~20ms slower.

config diff that causes slowdown ```diff diff --git a/.config/nvim/lua/init.lua b/.config/nvim/lua/init.lua index 0673d77..11e0864 100644 --- a/.config/nvim/lua/init.lua +++ b/.config/nvim/lua/init.lua @@ -304,24 +304,17 @@ require'lsp'.setup_lsps() create_mappings() create_autocmds() -require'bufferline'.setup { - highlights = { - bufferline_fill = { - -- guibg = gruvbox_material_palette.bg5[1]; - }; - }; -} +-- require'bufferline'.setup { +-- highlights = { +-- bufferline_fill = { +-- -- guibg = gruvbox_material_palette.bg5[1]; +-- }; +-- }; +-- } -require'statusline' +-- require'statusline' vim.defer_fn(function() - local gm_conf = vim.fn['gruvbox_material#get_configuration']() - local gruvbox_material_palette = - vim.fn['gruvbox_material#get_palette'](gm_conf.background, gm_conf.palette) - api.nvim_command('highlight SignColumn guibg=' .. gruvbox_material_palette.bg0[1]) - - require'colorizer'.setup() - require'mysnippets' require'nvim-todoist'.neovim_stuff.use_defaults() require'gitter'.neovim_stuff.use_defaults() end, 600) diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index 74b48bd..21b902f 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -1,5 +1,6 @@ vim.cmd [[packadd packer.nvim]] vim._update_package_paths() +vim.cmd [[ set termguicolors ]] require('packer').startup(function() local use = use @@ -16,7 +17,15 @@ require('packer').startup(function() use {'Raimondi/delimitMate', event = 'InsertEnter *'} use 'kyazdani42/nvim-web-devicons' - use 'Akin909/nvim-bufferline.lua' + use {'Akin909/nvim-bufferline.lua', config = [[ + require'bufferline'.setup { + highlights = { + bufferline_fill = { + -- guibg = gruvbox_material_palette.bg5[1]; + }; + }; + } + ]]} -- use 'junegunn/fzf' -- use 'junegunn/fzf.vim' @@ -28,7 +37,7 @@ require('packer').startup(function() use 'neovim/nvim-lspconfig' - use 'tjdevries/express_line.nvim' + use {'tjdevries/express_line.nvim', config = [[ require('statusline') ]]} use '/home/smolck/dev/lua/nlua.nvim' -- use 'tjdevries/nlua.nvim' @@ -57,7 +66,7 @@ require('packer').startup(function() -- use 'kdheepak/lazygit.vim' -- use 'neovimhaskell/haskell-vim' - use 'norcalli/nvim-colorizer.lua' + use {'norcalli/nvim-colorizer.lua', config = [[ require('colorizer').setup() ]]} use 'ntpeters/vim-better-whitespace' use 'sbdchd/neoformat' -- use 'sheerun/vim-polyglot' @@ -69,8 +78,13 @@ require('packer').startup(function() use 'tpope/vim-repeat' use 'tpope/vim-surround' - use 'sainnhe/gruvbox-material' + use {'sainnhe/gruvbox-material', config = [[ + local gm_conf = vim.fn['gruvbox_material#get_configuration']() + local gruvbox_material_palette = + vim.fn['gruvbox_material#get_palette'](gm_conf.background, gm_conf.palette) + api.nvim_command('highlight SignColumn guibg=' .. gruvbox_material_palette.bg0[1]) + ]]} - use 'norcalli/snippets.nvim' + use {'norcalli/snippets.nvim', config = [[ require('mysnippets') ]]} use 'norcalli/nvim_utils' end) ```

Is this slowdown unavoidable, or should it not be happening?

wbthomason commented 3 years ago

This is very strange; I would expect zero slowdown from these changes.

If you have a chance, could you diff your packer compiled file between these two versions as well, to make sure that nothing unexpected has changed there from the addition of config keys?

If it is (as expected) the exact same code running in both versions, then that would seem to indicate that it's slower to run this Lua in the heredoc packer generates than it is in a 100% Lua file.

I do also note that you're setting termguicolors in the new version too, but that shouldn't cost 20ms...

smolck commented 3 years ago

If you have a chance, could you diff your packer compiled file between these two versions as well, to make sure that nothing unexpected has changed there from the addition of config keys?

Only difference afaik is this extra code:

-- Config for: nvim-bufferline.lua
    require'bufferline'.setup {
      highlights = {
        bufferline_fill = {
          -- guibg = gruvbox_material_palette.bg5[1];
        };
      };
    }

-- Config for: nvim-colorizer.lua
 require('colorizer').setup() 
-- Config for: express_line.nvim
 require('statusline') 
-- Config for: gruvbox-material
    local gm_conf = vim.fn['gruvbox_material#get_configuration']()
    local gruvbox_material_palette =
      vim.fn['gruvbox_material#get_palette'](gm_conf.background, gm_conf.palette)
    api.nvim_command('highlight SignColumn guibg=' .. gruvbox_material_palette.bg0[1])

-- Config for: snippets.nvim
 require('mysnippets') 

I do also note that you're setting termguicolors in the new version too, but that shouldn't cost 20ms...

Yeah, need that for gruvbox-material to work properly ;)

wbthomason commented 3 years ago

I was just taking another look at this issue and noticed that some of the moved code was originally in a defer_fn call. I'd be surprised if that section of the code could account for a 20ms slowdown, but it occurs to me that this could absolutely account for some of the slowdown you notice here. Any chance that eliminates the issue?

wbthomason commented 3 years ago

@smolck: I'm going to close this for now, since I feel my theory above is plausible. If it's wrong, or you're still seeing this slowdown, please feel free to reopen!