Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nerdtree calls autoload functions on load which slows down vim startup time #276

Closed
idbrii opened this issue Jul 24, 2013 · 13 comments
Closed

Comments

@idbrii
Copy link

idbrii commented Jul 24, 2013

plugin/NERD_tree.vim calls several autoload functions: nerdtree#runningWindows, nerdtree#loadClassFiles, and nerdtree#postSourceActions.

Since these are called directly inside the plugin file, they'll be called on startup. This will cause nerdtree to slowdown vim startup time.

You may want to extract these files (and what they call) into another autoload file so a much smaller file is processed at runtime instead of all of autoload/nerdtree.vim.

Issue was created in response to an observation that nerdtree takes 30 ms to load.

@enterit
Copy link

enterit commented Aug 31, 2016

+1, NERDtree adds ~50ms to my VIM astertup

@antoinemadec
Copy link

Same here, NERDtree adds about 50ms to my startup time as well.
Is there any way to make it faster ?

Thanks for the geat plugin btw !

@lifecrisis
Copy link
Contributor

lifecrisis commented Sep 27, 2017

I can't speak for the other maintainers, but I see this as a very low-priority feature request. I can appreciate the desire for efficiency. We can't get carried away, though!

@PhilRunninger
Copy link
Member

I agree. 50 ms is hardly worth the effort of reducing in a scripting language.

@antoinemadec
Copy link

@PhilRunninger @lifecrisis , I completely understand.

50ms is nothing in terms of productivity, I agree.
However I would argue that, in terms of UX and smoothness, going from 150ms to 200ms when opening vim is still something that you "feel".

@lifecrisis
Copy link
Contributor

@antoinemadec. Technically speaking, this is totally feasible. It would be a simple matter of performing an orderly migration of the NERDTree code into the autoload/ directory.

However, the work would be time consuming and error prone (unless you could code a very accurate script to do it for you). Please keep in mind that we all do this for free!

@antoinemadec
Copy link

@lifecrisis once again, I completely understand !
Thanks a lot for the response :)

@MathiasSM
Copy link

It seems to me that it takes around 250ms on my computer. Might take even more on slower ones. Correct me if I'm wrong (I might be); here's nerd-tree specific output from vim --startuptime:

408.220  014.007  014.007: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/autoload/nerdtree.vim
433.908  022.422  022.422: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/path.vim
446.243  011.691  011.691: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/menu_controller.vim
447.370  000.480  000.480: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/menu_item.vim
458.072  010.194  010.194: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/key_map.vim
472.147  013.386  013.386: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/bookmark.vim
482.721  009.903  009.903: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/tree_file_node.vim
484.922  001.545  001.545: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/tree_dir_node.vim
497.354  011.945  011.945: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/opener.vim
502.318  004.399  004.399: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/creator.vim
503.725  000.779  000.779: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/flag_set.vim
514.160  009.832  009.832: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/nerdtree.vim
527.647  012.842  012.842: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/ui.vim
535.449  007.179  007.179: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/event.vim
540.791  004.587  004.587: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/lib/nerdtree/notifier.vim
554.335  012.839  012.839: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/autoload/nerdtree/ui_glue.vim
608.803  017.065  017.065: sourcing /Users/mathias/.vim/pack/mathias/start/zzz-vim-devicons/nerdtree_plugin/webdevicons.vim
626.017  015.925  015.925: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree-git-plugin/nerdtree_plugin/git_status.vim
637.919  011.529  011.529: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/nerdtree_plugin/exec_menuitem.vim
641.295  003.231  003.231: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/nerdtree_plugin/fs_menu.vim
642.190  263.290  067.510: sourcing /Users/mathias/.vim/pack/mathias/start/nerdtree/plugin/NERD_tree.vim

@PhilRunninger
Copy link
Member

If you use the vim-plug plugin manager, you can significantly reduce Vim's startup time, by delaying the sourcing of plugin packages. By adding the , { 'on': ... } parameter to the Plug command

silent! call plug#begin(expand('~/.vim/bundle'))
    Plug '[email protected]:scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
call plug#end()

my startup time went from 149ms to 119ms. My machine is fast enough that it doesn't make a noticeable difference, but using this delaying technique on as many plugins as possible can make a difference for you.

I don't know what difference it makes, if any, using Vim 8's packages vs. a plugin manager.

@antoinemadec
Copy link

Hi @PhilRunninger , thanks for the tip!
I have actually been using this trick for 6 months, and it works well.

The only issue is that I ended up not using NERDTree anymore.
Indeed, most of the time, I wanna use commands like :e %:h which uses netrw by default, until NERDTreeToggle is called (which I never do...).
I did not remove the plugin, and I even have a Function Key mapped to the toggle command, but I almost never use it 😞

Cheers,
Antoine

@PhilRunninger
Copy link
Member

I'm going to close this issue, since #851 seems to be the solution for it. Raise a new issue if necessary.

@solomonxie
Copy link

@PhilRunninger thanks for the help!
I don't know how it works, but just by simply replace Plug 'scrooloose/nerdtree' with Plug '[email protected]:scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }, it has dropped 20+ ms for the loading at startup!
Btw, it's buggy if I only do Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }.

@PhilRunninger
Copy link
Member

I've seen that bug as well. I never confirmed it, but I believe it comes down to Plug choosing to use the http: protocol and requiring your login credentials, whereas the git: protocol already has that information in your SSH config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants