nerdtree icon indicating copy to clipboard operation
nerdtree copied to clipboard

Please improve the performance.

Open kgfly opened this issue 2 years ago • 6 comments

Description

My folder has about 2k-3k files. When refreshing, it's very flow, taking about 4-5 seconds (on Windows OS). The refreshing appears to be a sync func. Etc during the refresh, whole vim get freezed, which makes auto fresh unusable, https://superuser.com/questions/1141994/autorefresh-nerdtree.

Also when expanding for the 1st time, it's very slow too.

Other plugin, such https://github.com/lambdalisue/fern.vim, is much faster (on Windows OS)

  1. Is it possible to improve the perf?
  2. Is it possible to change the sync mode to async? At least, the vim will not be freezed during the refresh.

Thanks.

kgfly avatar Apr 30 '23 19:04 kgfly

image

jinleileiking avatar Nov 24 '23 10:11 jinleileiking

@jinleileiking interesting results, May I ask what other plugins are there in your config other than NERDTree? For example vim-devicons or the nerdtree-git-plugin? and may I have your profiling options? This call takes a bunch of time because of being in a loop and getting called for every child node, I suspect that the actual bulk of the work happens in this line in the lib/nerdtree/path.vim line 664:

" FUNCTION: Path.refreshFlags(nerdtree) {{{1
function! s:Path.refreshFlags(nerdtree)
    call g:NERDTreePathNotifier.NotifyListeners('refreshFlags', self, a:nerdtree, {})
    call self.cacheDisplayString()
endfunction

Call to the refreshFlags listeners is for third-party plugins, for example, vim-devicons and nerdtree-git-plugin which update their internal state via this event. So the cost of each extra plugin is O(n).

rzvxa avatar Nov 24 '23 18:11 rzvxa

You can also try using #1362, Setting g:NerdTreeLazyDirRefresh to 1 enables the lazy refresh functionality. In this mode, we don't refresh closed directories, We just mark them as dirty and refresh them once it is necessary.

rzvxa avatar Nov 24 '23 18:11 rzvxa

Plug 'PhilRunninger/nerdtree-buffer-ops'

jinleileiking avatar Nov 28 '23 03:11 jinleileiking

It seems this plugin cost a lot of CPU. I disable this plugin, works well

jinleileiking avatar Nov 28 '23 03:11 jinleileiking

@jinleileiking I'm happy to hear that you've found the issue, Since it probably wasn't the original author's problem I'll leave this open.

rzvxa avatar Nov 29 '23 16:11 rzvxa