LoginSignup
9
7

More than 5 years have passed since last update.

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

Posted at

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などで起動を遅らせる処置が必要そうです。

9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7