LoginSignup
30
17

More than 5 years have passed since last update.

Vimのプロファイル機能を使って反応の悪いプラグインを特定する

Last updated at Posted at 2017-10-09

Clojureでの開発をNeoVim上で行う際、ファイルを開くのに時間がかかる場合があり、開発効率が落ちていました。その原因をVimのプロファイル機能を使って特定できたので、使い方を共有します。

手順

  • Vimを起動し、遅い動作の手前まで作業を進める。
  • 下記の3行をVimのコマンドウィンドウ内で入力する。
:profile start profile.log
:profile func *
:profile file *
  • 遅い動作を実行する。
  • 下記の2行をVimのコマンドウィンドウ内で入力する。
:profile pause
:noautocmd qall!
  • カレントディレクトリ内に profile.log が作成されているはずなので、その内容を確認する。ファイルの末尾に概要が出力されているので、そこから遅いロジックを特定していく。

profile.logの出力例

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    1   8.584595   0.000036  nerdtree#ui_glue#invokeKeyMap()
    1   8.584559   0.000131  77()
    1   8.568358   0.000042  76()
    1   8.568316   0.000028  <SNR>75_activateFileNode()
    1   8.568288   0.000047  105()
    1   8.568241   0.000034  122()
    1   8.568115   0.000017  175()
    1   8.568098   0.000055  176()
    1   8.488279   0.006735  16()
    2   8.093759   0.002042  ProjectionistDetect()
    2   7.712956   0.002847  projectionist#activate()
   40   7.418631   0.004057  projectionist#query()
   40   7.407037   2.785267  projectionist#query_raw()
   36   6.686320   0.001272  projectionist#query_exec()
    2   5.947827   0.001345  <SNR>168_query_exec_with_alternate()
48720   3.367385   2.290765  <SNR>168_match()
490400   1.252515             projectionist#lencmp()
97440   0.871693   0.602253  <SNR>168_slash()
    4   0.735650   0.000254  projectionist#query_file()
   17   0.457497   0.286622  provider#python#Call()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
   40   7.407037   2.785267  projectionist#query_raw()
48720   3.367385   2.290765  <SNR>168_match()
490400              1.252515  projectionist#lencmp()
97440   0.871693   0.602253  <SNR>168_slash()
   17   0.457497   0.286622  provider#python#Call()
   14              0.284700  <SNR>166_nrepl_transport_dispatch()
97606              0.269994  projectionist#slash()
48720              0.202756  <SNR>168_startswith()
    1   0.170747   0.170734  provider#pythonx#Require()
    2   0.171497   0.150765  projectionist#navigation_commands()
    8              0.108033  projectionist#define_navigation_command()
    2   0.377909   0.044814  <SNR>152_projectionist_detect()
    1              0.028492  <SNR>95_DirenvExport()
  752              0.028444  <SNR>130_get_syn()
  376   0.058135   0.025600  airline#highlighter#get_highlight()
 2436              0.020623  <SNR>168_gsub()
    5   0.018016   0.017663  fireplace#ns()
   18              0.014815  <SNR>106_Highlight_Matching_Pair()
  168   0.043886   0.013509  airline#highlighter#exec()
    1   0.012891   0.012863  ctrlp#utils#writecache()

この場合は、vim-projectionistという、プロジェクトのファイル構成を分析してファイル操作を支援したり、ソースファイルとテストファイル間のジャンプを実現してくれるプラグインに時間がかかっていることがわかります。私は最近では、ctrlpというプラグインでファイル操作を主に行っているので、このプラグインをコメントアウトすることにし、動作速度の改善を図ることができました。

30
17
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
30
17