konafx / dotfiles

1 stars 0 forks source link

neovim設定ファイルを修正して、読み込みの高速化 #16

Open konafx opened 1 year ago

konafx commented 1 year ago

あんま気にしてなかったけど、一応計測した

> vim-startuptime -vimpath nvim -count 100
Extra options: []
Measured: 100 times

Total Average: 293.833630 msec
Total Max:     570.498000 msec
Total Min:     257.358000 msec

   AVERAGE        MAX       MIN
--------------------------------
105.605420 251.685000 91.612000: /home/konafx/.config/nvim/plugin/packer_compiled.lua
 46.986220 119.940000 36.901000: /home/konafx/.config/nvim/init.lua
 38.213520 107.099000 29.722000: require('plugins')
 37.205550  98.840000 31.680000: require('octo.pickers.telescope.provider')
 29.438830  90.383000 22.841000: /usr/share/nvim/runtime/autoload/provider/python3.vim
 21.207030  55.716000 18.382000: /home/konafx/.config/nvim/after/plugin/luasnip.rc.lua
 20.657110  63.666000 17.272000: require('octo.pickers.telescope.previewers')
 20.246680  62.989000 16.931000: require('telescope.previewers')
 18.822390  34.758000 14.246000: /home/konafx/.config/nvim/after/plugin/mason-null-ls.rc.lua
 18.006580  59.835000 14.357000: require('octo')
 12.846610  31.647000 10.979000: /home/konafx/.config/nvim/after/plugin/neogit.rc.lua
 12.351190  30.939000 10.556000: require('neogit')
 11.801740  29.178000  9.936000: require('telescope.previewers.buffer_previewer')
 10.960380  29.645000  9.344000: require('rc/gitsigns')

octo使ってないからoptにすることにした

konafx commented 1 year ago
❯ vim-startuptime -vimpath nvim -count 100
Extra options: []
Measured: 100 times

Total Average: 260.371220 msec
Total Max:     489.428000 msec
Total Min:     232.662000 msec

  AVERAGE        MAX       MIN
-------------------------------
58.173970 138.235000 50.818000: /home/konafx/.config/nvim/plugin/packer_compiled.lua
44.090000  93.526000 36.938000: /home/konafx/.config/nvim/init.lua
36.011380  81.009000 29.836000: require('plugins')
28.018920  67.329000 22.962000: /usr/share/nvim/runtime/autoload/provider/python3.vim
27.731430  54.603000 23.410000: /home/konafx/.config/nvim/after/plugin/telescope.rc.lua
21.863610  60.612000 18.658000: require('rc/gitsigns')
20.715880  36.068000 18.207000: /home/konafx/.config/nvim/after/plugin/luasnip.rc.lua
15.353790  31.718000 12.915000: require('trouble')
15.163740  66.177000 13.364000: /home/konafx/.config/nvim/after/plugin/neogit.rc.lua
14.681100  65.413000 12.869000: require('neogit')
13.807530  27.619000 11.173000: require('telescope.actions')
13.768380  44.454000 12.305000: /home/konafx/.config/nvim/after/plugin/mason-null-ls.rc.lua
12.837190  27.986000 10.905000: require('trouble.view')
12.313520  27.162000 10.447000: require('trouble.renderer')
11.589330  25.827000  9.830000: require('trouble.providers')

min timeはあんまり変わらず telescopeの設定ファイルが重いのは、使わないかもしれない file_browserを読み込んでるからか?

konafx commented 1 year ago

https://github.com/wbthomason/packer.nvim/blob/master/lua/packer.lua

これ読んで修正しよう plugins.lua

konafx commented 1 year ago

https://github.com/wbthomason/packer.nvim/blob/1d0cf98a561f7fd654c970c49f917d74fafe1530/lua/packer.lua#L989

packer.startup = function(spec)

https://github.com/wbthomason/packer.nvim/blob/1d0cf98a561f7fd654c970c49f917d74fafe1530/lua/packer.lua#L995-L1012 いろんな呼び出し方があるっぽい

自分のは https://github.com/konafx/dotfiles/blob/7060a047db3992d238115480473704e857803971/nvim/lua/plugins.lua#L9 でfunctionだからspec[1]user_funcに入る。

https://github.com/wbthomason/packer.nvim/blob/1d0cf98a561f7fd654c970c49f917d74fafe1530/lua/packer.lua#L1018-L1024

  if user_func then
    setfenv(user_func, vim.tbl_extend('force', getfenv(), { use = packer.use, use_rocks = packer.use_rocks }))
    local status, err = pcall(user_func, packer.use, packer.use_rocks)
    if not status then
      log.error('Failure running setup function: ' .. vim.inspect(err))
      error(err)
    end

useを使って読み込むので、次はuseを読む

konafx commented 1 year ago

https://github.com/wbthomason/packer.nvim/blob/1d0cf98a561f7fd654c970c49f917d74fafe1530/lua/packer.lua#L334-L340

--- Add a plugin to the managed set
packer.use = function(plugin_spec)
  plugin_specifications[#plugin_specifications + 1] = {
    spec = plugin_spec,
    line = debug.getinfo(2, 'l').currentline,
  }
end

plugin_specificationsリストにpushしてるだけっぽい

https://github.com/wbthomason/packer.nvim/blob/1d0cf98a561f7fd654c970c49f917d74fafe1530/lua/packer.lua#L342-L350

local function manage_all_plugins()
  local log = require_and_configure 'log'
  log.debug 'Processing plugin specs'
  if plugins == nil or next(plugins) == nil then
    for _, spec in ipairs(plugin_specifications) do
      manage(spec)
    end
  end
end

ここでmanageに渡している

manageでようやっとasやらrequiresやらを見ている。 https://github.com/wbthomason/packer.nvim/blob/1d0cf98a561f7fd654c970c49f917d74fafe1530/lua/packer.lua#L189

konafx commented 1 year ago

as: nameになる

opt: https://github.com/wbthomason/packer.nvim/blob/1d0cf98a561f7fd654c970c49f917d74fafe1530/lua/packer.lua#L238-L244

  -- Some config keys modify a plugin type
  if plugin_spec.opt then
    plugin_spec.manual_opt = true
  elseif plugin_spec.opt == nil and config.opt_default then
    plugin_spec.manual_opt = true
    plugin_spec.opt = true
  end

そもそも main (packer v2)は別のブランチだった https://github.com/wbthomason/packer.nvim/blob/main/lua/packer.lua