Install Theme

Your web-browser is very outdated, and as such, this website may not display properly. Please consider upgrading to a modern, faster and more secure browser. Click here to do so.

タンブラー?

Big Sky

3月 15 '12

vimrcのどこが重いのかを調べられるプラグイン書いた。

Vimには --startuptime というコマンドラインオプションがあり
$ vim —startuptime=foo
の様に指定するとスクリプトファイル単位で掛かった時間を知る事が出来ます。
times in msec
 clock   self+sourced   self:  sourced script
 clock   elapsed:              other lines

000.000  000.000: —- VIM STARTING —-
000.000  000.000: Allocated generic buffers
000.000  000.000: locale set
000.000  000.000: clipboard setup
000.000  000.000: window checked
000.000  000.000: inits 1
000.000  000.000: parsing arguments
000.000  000.000: expanding arguments
000.000  000.000: shell init
016.000  016.000: Termcap init
016.000  000.000: inits 2
016.000  000.000: init highlight
016.000  000.000  000.000: sourcing c:\vim\runtime\syntax\syncolor.vim
016.000  000.000  000.000: sourcing c:\vim\runtime\syntax\synload.vim
062.000  000.000  000.000: sourcing c:\go\misc\vim\ftdetect\gofiletype.vim
062.000  000.000  000.000: sourcing c:\temp\github\rust\src\etc\vim\ftdetect\rust.vim
062.000  000.000  000.000: sourcing c:\temp\bitbucket\vimclojure\vim\ftdetect\clojure.vim
062.000  046.000  046.000: sourcing c:\vim\runtime\filetype.vim
062.000  046.000  000.000: sourcing c:\vim\runtime\syntax\syntax.vim
062.000  000.000  000.000: sourcing c:\vim\runtime\filetype.vim
062.000  000.000  000.000: sourcing c:\vim\runtime\ftplugin.vim
062.000  000.000  000.000: sourcing c:\vim\runtime\indent.vim
062.000  000.000  000.000: sourcing c:\vim\runtime\ftplugof.vim
しかし幾ら不必要なプラグインを削っても起動が遅い事があります。そんな場合はだいたいvimrcの読み込みに時間が掛かっていたりします。
218.000  202.000  093.000: sourcing $HOME\_vimrc
じゃぁ _vimrc の中のどの部分が時間が掛かってるのよ…となるのですが、--startuptime では実行行単位に計測はしてくれません。これをなんとかしたかったので benchvimrc-vim というプラグインを書きました。
mattn/benchvimrc-vim - GitHub

make benchmark result of your vimrc

http://bit.ly/xdO5as
これをインストールして
:BenchVimrc
を実行すると、行単位に計測時間が表示されます。
00692           : ”**************************************************
00693           : ”* Syntax On {{{
00694           : ”—————————————————————————
00695           : if isdirectory($VIMRUNTIME.‘/syntax’)
00696           :   if &t_Co > 2 || has(“gui_running”)
00697   0.025281:     syntax on
00698           :   endif
00699           :   if has(“autocmd”)
00700   0.013719:     filetype plugin indent on
00701           :   endif
00702   0.000107:   autocmd BufReadPost *
00703           :     \ silentif line(”’"”) > 0 && line(”’"”) <= line(”$”) |
00704           :     \   exe “normal g`"” |
00705           :     \ endif
00706           : endif
00707           : 
00708   0.004691filetype plugin off
先頭に計測時間が付与されています。実行していない行にはもちろん計測時間はついていません。
数値が先頭なので
:%sort
を実行すると一番下に、重い処理が集まります。私のvimrcの例だと
  0.004190 00132let &viewdir=globpath(&rtp, “view”)
  0.004294 00796:   silentcall metarw#define_wrapper_commands(1)
  0.004459 00133let &undodir=globpath(&rtp, “undo”)
  0.004778 00708filetype plugin off
  0.005199 00464let g:skk_large_jisyo = globpath(&rtp, “dict/SKK-JISYO.L”)
  0.013917 00700:     filetype plugin indent on
  0.014531 00731:   silentcolorscheme torte
  0.025083 00697:     syntax on
  0.053559 00716:   call pathogen#infect()
  0.375485 00717:   call pathogen#helptags()
こうなりました。どうやら pathogen#helptags に 0.4秒掛かっているようです。新しいプラグインを入れたとき、自動でヘルプタグを作ってくれるので便利ですが、プラグインの更新時や新しいプラグインを入れた際に自分で実行すればいいだけなので、ひとまずコメントアウトしてみます。
vimrc の読み込みに時間が掛かって困ってる人には便利かもしれません。注意点としては、初回実行という訳ではないので完全な計測では無い事、if文内の式には現状対応出来ていない事です。よろしければどうぞ。


from Big Sky http://bit.ly/wKZvXW

6 リアクション

  1. bakedroysaitamanodorujiからリブログしました
  2. nbbbsaitamanodorujiからリブログしました
  3. saitamanodorujimattnからリブログしました
  4. k32rumattnからリブログしました
  5. mattnの投稿です