Help us understand the problem. What is going on with this article?

vim/neovimの起動時間・プラグイン読込時間を調べる

nvim, vimの起動時間を調べるには起動時に --startuptime オプションをつけて起動します。
最後の引数はログを書き込むファイルパスです。

$ nvim --startuptime ./startup.log
$ vim --startuptime ./startup.log

nvim(,vim)ログを表示してみます。:e startup.log

nvim_--startuptime_startup.log
times in msec
 clock   self+sourced   self:  sourced script
 clock   elapsed:              other lines

000.057  000.057: --- NVIM STARTING ---
000.657  000.600: locale set
006.141  005.484: inits 1
006.167  000.026: window checked
006.400  000.233: parsing arguments
006.471  000.072: expanding arguments
006.537  000.065: inits 2
008.823  002.287: init highlight
008.971  000.034  000.034: sourcing $VIM/sysinit.vim
009.409  000.272  000.272: sourcing /home/vagrant/.config/nvim/autocmd.rc.vim
009.660  000.153  000.153: sourcing /home/vagrant/.config/nvim/keymap.rc.vim
029.147  000.064  000.064: sourcing /usr/share/vim/vimfiles/ftdetect/dockerfile.vim
029.239  000.047  000.047: sourcing /usr/share/vim/vimfiles/ftdetect/pullrequest.vim
029.382  018.686  018.574: sourcing /usr/share/nvim/runtime/filetype.vim
...長いので割愛

どのプラグインがボトルネックになっているか調べたかったので、各プラグインの読込時間順に並べます。
1列目が起動時間の累積和, 2列目が各プラグイン読込にかかる時間なので、2列目でソートしてやると各プラグインの読込時間を調べることができます。

:%!sort -k2nr
nvim_--startuptime_startup.log_sorted
1003.628  404.487: VimEnter autocommands
181.330  172.312  002.493: sourcing /home/vagrant/.config/nvim/init.vim
179.070  136.496  016.331: sourcing /home/vagrant/.local/share/dein/state_nvim.vim
167.905  117.085  116.138: sourcing /usr/share/nvim/runtime/autoload/provider/python3.vim
484.293  085.625  081.062: sourcing /home/vagrant/.local/share/dein/.cache/init.vim/.dein/plugin/yankring.vim
233.473  052.029  001.100: sourcing /usr/share/nvim/runtime/syntax/syntax.vim
397.464  048.698  048.698: sourcing /home/vagrant/.local/share/dein/.cache/init.vim/.dein/plugin/unimpaired.vim
563.897  039.847: opening buffers
282.280  039.627  019.037: sourcing /home/vagrant/.local/share/dein/.cache/init.vim/.dein/plugin/NERD_tree.vim
232.993  034.920  033.932: sourcing /usr/share/nvim/runtime/filetype.vim
1035.363  031.718: first screen update

...長いので割愛

 clock   elapsed:              other lines
 clock   self+sourced   self:  sourced script
times in msec

上位に挙がってくるプラグインはlazyやon_eventなどで起動を遅らせる処置が必要そうです。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away