“Slow” by goesberlin. Creative Commons by-nc-nd license Some rights reserved.

Profiling Vim

Finding out which plugin is making Vim slow

I like Vim because it’s very fast. Unfortunately the other day I found myself opening a diff file that took forever to load. The file had 58187 (this number will be important later on) lines in it but I never thought Vim would choke with something that was less than 2M size.

If you find yourself in a similar situation this is what you can do in order to find out what is causing Vim to slow down:

  1. Open Vim and start the profiling
:profile start /tmp/profile.log
:profile func *
:profile file *

This tells Vim to save the results of the profile into `/tmp/profile.log` and to run the profile for every file and function.

2. Then do the action that was taking a long time in Vim, in my case opening the diff file.

:edit /tmp/file.diff
:profile pause
:q!

Note: The `profile.log` file only gets generated until you close Vim.

3. Now you can open `profile.log` and analyze the data. There is a lot of information in this file but you can start by focusing on the `Total time`. In my case there was a clear offender with a total time of more than 14 seconds!

FUNCTION <SNR>24_PreviewColorInLine() 
Called 58187 times
Total time: 14.430544
Self time: 2.961442

Remember the number of lines in the file. For me it was interesting to see that the function gets called just as many times.

4. Finding out where this function is defined is very easy thanks to the <SNR> tag and the number right after it. You simply need to run :scriptnames and scroll until you find the index number you are looking for, in my case 24.

24: ~/.vim/bundle/colorizer/autoload/colorizer.vim

I personally don’t think the benefit that a plugin can bring is acceptable at the cost of making trivial functionality like opening a file take as long as quarter of a minute. But with the knowledge of which function is causing the problem you can get to the task of fixing it as well.


Thanks for staying this long with me and if you found this information useful please give it some ❤