Vim plugins and startup time
2014. 07. 21.

Have you noticed lately that your Vim doesn't start as quickly as it used to be? If so, that's probably because you have installed a bunch of plugins over time. A typical Vim plugin shouldn't take longer than a few milliseconds to load (there are a few exceptions, most notably, NERDtree) but they can add up to make a noticeable difference as these days, it's not uncommon to see a Vim user equipped with a several dozens of plugins.

So let's see how plugins affect the startup time of Vim. Since we have a few options for how we load plugins, I'm going to measure the startup times of four Vim configurations that only differ in the choice of their plugin managers, in addition to the one that does not use any plugins. Pathogen, Vundle, NeoBundle, and vim-plug are the plugin managers used.

The configurations are based on my own Vim configuration at the time of the writing. It has over 1,200 lines of Vimscript and loads 37 plugins. The result is given as follows. Each number shown is the average of 100 measurements.

We can definitely see that having plugins do make a clearly observable difference in the startup time of Vim. However, you may argue that the difference is practically negligible considering the fact that modern IDEs easily take tens of seconds to load. It's a perfectly valid point especially if you prefer to keep your Vim up all the time. But if your workflow involves many short-lived Vim sessions, you will frequently notice the delay, and it can be quite annoying. (Or not. We all have different levels of tolerance.)

Let's take a closer look at the result. It shows that the choice of the plugin manager also affects the startup time. Unsurprisingly, Vim with Pathogen was the fastest to start: 235ms. Pathogen is the simplest of the four, and requires only one function call while other plugin managers require at least 37 commands for declaring the use of plugins. So I would've been very surprised if it took longer than the alternatives. Vim with Vundle took 252ms to start, which is 7.2% longer than the case with Pathogen. vim-plug was slightly faster and took 243ms. NeoBundle, which has the broadest set of features, exhibited 21% overhead compared to Pathogen and required 284ms.

But wait, that's not the whole story. NeoBundle and vim-plug both have the ability to defer loading of plugins until they are actually used. The concept is called lazy loading or on-demand loading. Think about it. How many plugins do you use regularly? You'll notice that many of the plugins you have in your arsenal aren't actually used during the lifetime of a typical Vim process, and it makes perfect sense to load them only when you actually need them. On-demand loading (or lazy loading) also has the benefit of keeping your Vim session clean.

So let's try it. The following chart also shows the result with on-demand loading applied.

By not loading plugins that are not immediately needed, NeoBundle and vim-plug both managed to reduce the startup times by around 107ms. vim-plug now takes only 135ms to start.

You may not understand all these efforts and obsession over a miniscule amount of time, but seriously, I really love it when my Vim feels snappy.

» capture | close