nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua
Other
7.18k stars 610 forks source link

Slows down when save and quit changed file #172

Closed fitrh closed 3 years ago

fitrh commented 3 years ago

https://user-images.githubusercontent.com/55179750/104080690-78185580-5264-11eb-9bc2-49b7fa66b781.mp4

This is suddenly happen and i don't know what caused them, save and quit (:wq) a changed file give some delay, after disable this plugin, it back normal again. But this is not happen if doing save(:w) and quit(:q) separately. I use the default configuration from README.

kyazdani42 commented 3 years ago

Not sure why this happens. I did not manage to reproduce properly because my computer's too fast. Could you tell me which commit caused the issue ?

fitrh commented 3 years ago

I think since the last commit of neovim, recently i just rebuild my neovim with the latest commit and also update this plugin, the problem still remains, but now, a little bit faster, and it's only happens with :wq, for now, i just stick with :w then :q.

fitrh commented 3 years ago

This is what is looks like from the latest commit of neovim

https://user-images.githubusercontent.com/55179750/104137030-d95f3680-53d4-11eb-8b5b-94b336620c1a.mp4

kyazdani42 commented 3 years ago

i meant which commit of nvim-tree introduces this anomaly ?

fitrh commented 3 years ago

I think it's 86944b51c0e0a8fed5a02ab44640b2b215cebe93, but, isn't that just a renaming ?

kyazdani42 commented 3 years ago

don't think it should change anything related to saving. There might be an issue with some async stuff on buf change.

pesader commented 3 years ago

I'm having the same issue. When nvim-tree is loaded, it takes a long time to write a file for the first time in a given session, but the following :w work as expected. For me, nvim freezes on :w as well :wq.

In any case, thank you for developing nvim-tree! Aside from this issue, it's the best explorer plugin I've ever used.

kyazdani42 commented 3 years ago

thanks @PeSader :) yes i've seen this happening too on my other computer, i might just push a fix when i have some time

sbulav commented 3 years ago

I had similar issue with vim-startify and g:nvim_tree_follow set to True. For me setting g:nvim_tree_follow to False fixed the issue.

fitrh commented 3 years ago

I had similar issue with vim-startify and g:nvim_tree_follow set to True. For me setting g:nvim_tree_follow to False fixed the issue.

Try this on my build, but the issue still exist

kyazdani42 commented 3 years ago

if someone wish to debug this issue, because i'm quite busy at the moment and will not be able to work on this project for at least a month or so.

kyazdani42 commented 3 years ago

should be fixed in latest master, can you confirm ?

fitrh commented 3 years ago

Thank you, it's fixed in my machine, can you tell me which commit is that ? i see there are 3 commit from you.

kyazdani42 commented 3 years ago

it's been fixed in 42a875aa006239d5b688f56ac37ff58c5aab1b69 !

kpritam commented 3 years ago

I am not sure if this issue got reintroduced again. Couple weeks back, all was working normal. But recently I have observed very slow startup time, file update/save takes lot of time if I enable this plugin. Issues looks similar to what mentioned in this thread.

kyazdani42 commented 3 years ago

I've seen that too, not sure which commit introduced this but i've got quite a few features submissions lately which might have introduced some lag.

kyazdani42 commented 3 years ago

although startup time should not be that high, i did not notice anything strange during startup.

kpritam commented 3 years ago

No sure but I am consistently able to reproduce startup time delay (and it is so much noticeable ;)) by enabling/disabling nvim-tree plugin.

kyazdani42 commented 3 years ago

just did some debugging, without nvim-tree, when :qa nvim still freezes for half a second so it does not come from this plugin. also did some benchmark on most functions:

perf stats ``` executed set_index_and_redraw in 0.014286ms executed set_mappings in 0.2068ms executed open in 3.580817ms executed init in 14.469638ms executed get_node_at_cursor in 0.030105ms executed get_node_at_line in 0.004106ms executed unroll_dir in 2.732938ms executed get_node_at_cursor in 0.034735ms executed get_node_at_line in 0.001362ms executed unroll_dir in 1.557727ms executed get_node_at_cursor in 0.027301ms executed get_node_at_line in 0.001574ms executed unroll_dir in 2.462568ms executed get_node_at_cursor in 0.021391ms executed get_node_at_line in 0.001461ms executed unroll_dir in 2.105733ms executed get_node_at_cursor in 0.021305ms executed get_node_at_line in 0.0016ms executed set_index_and_redraw in 0.185944ms executed win_focus in 0.300206ms executed set_index_and_redraw in 0.14758ms executed win_focus in 0.363682ms executed open_file in 31.600438ms executed refresh_nodes in 0.024101ms executed refresh_nodes in 0.096194ms executed refresh_nodes in 0.119678ms executed refresh_nodes in 0.193364ms executed refresh_nodes in 0.217475ms executed git in 0.003102ms executed git in 0.003324ms executed git in 0.002931ms executed git in 0.003047ms executed git in 0.002888ms executed git in 0.00289ms executed git in 0.002675ms executed git in 0.012622ms executed git in 0.002789ms executed git in 0.013802ms executed git in 0.024958ms executed git in 0.002959ms executed git in 0.002838ms executed git in 0.00278ms executed git in 0.002825ms executed git in 0.00278ms executed git in 0.002889ms executed git in 0.01537ms executed git in 0.02088ms executed git in 0.003214ms executed git in 0.015009ms executed refresh_tree in 11.275239ms executed refresh_nodes in 0.033736ms executed refresh_nodes in 0.095541ms executed refresh_nodes in 0.122274ms executed refresh_nodes in 0.146589ms executed refresh_nodes in 0.168265ms executed git in 0.003397ms executed git in 0.003706ms executed git in 0.003159ms executed git in 0.003106ms executed git in 0.002958ms executed git in 0.002937ms executed git in 0.002682ms executed git in 0.012136ms executed git in 0.002971ms executed git in 0.018298ms executed git in 0.033982ms executed git in 0.003016ms executed git in 0.002945ms executed git in 0.002887ms executed git in 0.002889ms executed git in 0.002808ms executed git in 0.002894ms executed git in 0.017878ms executed git in 0.002936ms executed git in 0.002892ms executed git in 0.015768ms executed refresh_tree in 12.27444ms executed refresh_nodes in 0.019506ms executed refresh_nodes in 0.067027ms executed refresh_nodes in 0.092037ms executed refresh_nodes in 0.115805ms executed refresh_nodes in 0.160765ms executed git in 0.003274ms executed git in 0.022259ms executed git in 0.00334ms executed git in 0.0033ms executed git in 0.003204ms executed git in 0.003219ms executed git in 0.002709ms executed git in 0.01237ms executed git in 0.003078ms executed git in 0.045786ms executed git in 0.076259ms executed git in 0.003159ms executed git in 0.003176ms executed git in 0.003049ms executed git in 0.002982ms executed git in 0.003178ms executed git in 0.012575ms executed git in 0.053707ms executed git in 0.003105ms executed git in 0.002944ms executed git in 0.035131ms executed refresh_tree in 12.052133ms executed set_index_and_redraw in 0.008399ms executed set_mappings in 0.215332ms executed open in 4.37328ms executed init in 17.55265ms executed set_index_and_redraw in 0.017806ms executed set_mappings in 0.271736ms executed open in 4.258278ms executed init in 39.087481ms executed get_node_at_cursor in 0.048792ms executed get_node_at_line in 0.006016ms executed unroll_dir in 1.967907ms executed get_node_at_cursor in 0.026295ms executed get_node_at_line in 0.002788ms executed set_index_and_redraw in 0.146058ms executed win_focus in 0.307013ms executed set_index_and_redraw in 0.139007ms executed win_focus in 0.489602ms executed open_file in 34.400398ms executed close in 0.05891ms executed refresh_nodes in 0.199486ms executed refresh_nodes in 0.372352ms executed git in 0.014427ms executed git in 0.035326ms executed git in 0.209322ms executed git in 0.015511ms executed git in 0.307978ms executed refresh_tree in 58.460001ms executed set_index_and_redraw in 0.010283ms executed set_mappings in 0.200568ms executed open in 4.569551ms executed init in 5.265718ms executed set_index_and_redraw in 0.469ms executed set_index_and_redraw in 0.13292ms executed set_index_and_redraw in 0.10726ms executed set_index_and_redraw in 0.748014ms executed refresh_nodes in 0.170664ms executed refresh_nodes in 0.421875ms executed git in 0.002837ms executed git in 0.00325ms executed git in 0.030933ms executed git in 0.002909ms executed git in 0.024134ms executed refresh_tree in 32.158817ms executed refresh_nodes in 0.368436ms executed refresh_nodes in 0.524154ms executed git in 0.002749ms executed git in 0.003132ms executed git in 0.020727ms executed git in 0.00293ms executed git in 0.023273ms executed refresh_tree in 14.407648ms executed set_index_and_redraw in 0.007546ms executed set_mappings in 0.190542ms executed open in 4.194099ms executed init in 4.86708ms executed set_index_and_redraw in 0.485022ms executed set_index_and_redraw in 0.110644ms executed set_index_and_redraw in 0.394769ms executed set_index_and_redraw in 0.651006ms executed refresh_nodes in 0.263819ms executed refresh_nodes in 0.447718ms executed git in 0.002809ms executed git in 0.003364ms executed git in 0.022162ms executed git in 0.003121ms executed git in 0.024229ms executed refresh_tree in 20.567574ms executed init in 0.343831ms executed set_mappings in 0.846603ms executed open in 18.54142ms executed refresh_nodes in 0.157758ms executed refresh_nodes in 0.34223ms executed git in 0.002669ms executed git in 0.003243ms executed git in 0.024558ms executed git in 0.002962ms executed git in 0.021516ms executed refresh_tree in 23.912883ms executed refresh_nodes in 0.844378ms executed refresh_nodes in 1.306042ms executed git in 0.002808ms executed git in 0.015ms executed git in 0.057235ms executed git in 0.007349ms executed git in 0.089568ms executed refresh_tree in 46.367212ms executed refresh_nodes in 0.092934ms executed refresh_nodes in 0.32884ms executed git in 0.002904ms executed git in 0.064252ms executed git in 0.229189ms executed git in 0.061166ms executed git in 0.23899ms executed refresh_tree in 14.509901ms executed init in 51.962241ms executed refresh_nodes in 0.221846ms executed refresh_nodes in 0.658822ms executed git in 0.013009ms executed git in 0.442387ms executed git in 1.751572ms executed git in 0.247742ms executed git in 0.643867ms executed refresh_tree in 62.695052ms executed open in 12.150813ms executed win_focus in 0.020231ms executed set_index_and_redraw in 0.500202ms executed get_node_at_cursor in 0.022435ms executed get_node_at_line in 0.00187ms executed set_index_and_redraw in 0.137702ms executed win_focus in 0.2035ms executed set_index_and_redraw in 0.087902ms executed win_focus in 0.556675ms executed open_file in 40.507851ms executed refresh_nodes in 0.29845ms executed refresh_nodes in 0.539117ms executed git in 0.002751ms executed git in 0.030455ms executed git in 0.070886ms executed git in 0.02453ms executed git in 0.066677ms executed refresh_tree in 49.970539ms executed set_index_and_redraw in 0.105371ms executed refresh_nodes in 0.163981ms executed refresh_nodes in 0.316805ms executed git in 0.002872ms executed git in 0.003351ms executed git in 0.028246ms executed git in 0.003061ms executed git in 0.026309ms executed refresh_tree in 39.403048ms executed set_index_and_redraw in 0.027648ms executed set_mappings in 0.232251ms executed open in 4.674559ms executed init in 16.115769ms executed init in 13.873963ms executed refresh_nodes in 0.151927ms executed refresh_nodes in 0.308159ms executed git in 0.003173ms executed git in 0.00335ms executed git in 0.026202ms executed git in 0.003028ms executed git in 0.025411ms executed refresh_tree in 45.458063ms executed refresh_nodes in 0.17945ms executed refresh_nodes in 0.292504ms executed git in 0.002882ms executed git in 0.024891ms executed git in 0.065641ms executed git in 0.007232ms executed git in 0.035578ms executed refresh_tree in 13.711638ms executed set_index_and_redraw in 0.11759ms ```

and haven't seen any lag, all those values are quite fast, debugging for 1/2h i've seen at most 15ms for refresh. So i don't think the lags come from nvim-tree, i'll do some more debugging to see where it comes from

kyazdani42 commented 3 years ago

ok for me, the efm setup for nvim-lspconfig is the culprit of my :qa huge lag. could you try #278 and tell me how long the init calls take to run on your machine ?

gegoune commented 3 years ago

There is a known bug. with older version of efm-langserver which causes delay on disconnect. Updating to 0.0.28 should resolve it.

kpritam commented 3 years ago

Tried #278, same result, my startup hungs when plugin is enabled. Below images show difference of almost 8 seconds

Without plugin: image

With Plugin: image

I am using NVIM v0.5.0-dev+nightly-71-g48e805728 And this nvim config as is : https://github.com/ChristianChiarulli/nvcode Above difference is just by commenting out 'kyazdani42/nvim-tree.lua' line from plugins.lua file

kpritam commented 3 years ago

There is a known bug. with older version of efm-langserver which causes delay on disconnect. Updating to 0.0.28 should resolve it.

Tried this but same result. image

kyazdani42 commented 3 years ago

it uses packer so i believe once you've commented out, you need to :PackerCompile to properly reload the config. I've never seen such startup times, and this plugin is really doing nothing special. If you can pinpoint the culprit in the configuration i'd be happy to fix this.

kyazdani42 commented 3 years ago

what kind of specs do you have ? My machines might be too powerful thus i'm not distinguishing any lag ^^'

kpritam commented 3 years ago

what kind of specs do you have ? My machines might be too powerful thus i'm not distinguishing any lag ^^'

I have MacBookPro, 8 Core i9, 32 GB Memory 😉

kyazdani42 commented 3 years ago

this plugin should definitely not be the one to do the lag. 6second is way too much. What neovim version are you running ?

kpritam commented 3 years ago

this plugin should definitely not be the one to do the lag. 6second is way too much. What neovim version are you running ?

NVIM v0.5.0-dev+nightly-71-g48e805728
Build type: Release
LuaJIT 2.1.0-beta3
kyazdani42 commented 3 years ago

could you reproduce the lag with a minimal configuration ?

kpritam commented 3 years ago

Following init.lua script reproduces this on my machine

local execute = vim.api.nvim_command
local fn = vim.fn

local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'

if fn.empty(fn.glob(install_path)) > 0 then
    execute('!git clone https://github.com/wbthomason/packer.nvim ' .. install_path)
    execute 'packadd packer.nvim'
end

local my = function(file) require(file) end

vim.cmd 'autocmd BufWritePost plugins.lua PackerCompile' -- Auto compile when there are changes in plugins.lua

require('packer').init({display = {auto_clean = false}})

return require('packer').startup(function(use)
  use 'wbthomason/packer.nvim'
  use 'kyazdani42/nvim-tree.lua'
end)
kyazdani42 commented 3 years ago

can definitely not reproduce :( my luajit version is 2.0.5, would that change something ?

kpritam commented 3 years ago

can definitely not reproduce :( my luajit version is 2.0.5, would that change something ?

Somehow its failing to install on my machine with following error :(

clang: error: linker command failed with exit code 1 (use -v to see invocation)
kpritam commented 3 years ago

I tried this on virtualbox, and everything works perfect.

Could this be OS specific. I am observing slowness on following configuration:

kpritam commented 3 years ago

Turns out, somehow my fish variables file had almost 900 lines agains fish user path variable. That was causing nvimtree to render pretty slow. Not sure nvim tree somehow uses use shells path?

@kyazdani42 If you dont see any other issue, this can be closed, thanks for the quick replies.

kyazdani42 commented 3 years ago

i tried fish but it did not change anything, maybe you are using it inside neovim (which is not a good idea) ? what is the output of :set shell? after you launch neovim ?

kpritam commented 3 years ago

maybe you are using it inside neovim (which is not a good idea) ?

Is it so, I had no idea, do you have any pointer where I can read more.

what is the output of :set shell? after you launch neovim ?

Yes, its fish. But after I reset entire fish settings, I am not observing much lag though.

kyazdani42 commented 3 years ago

well you should not use fish as neovim base shell, it might break plugins that use shell commands :) just set shell=/bin/bash or something like that in your nvim config would then solve this. Also fish is quite slow as a shell for executing commands, this is why maybe git commands would take some time to spawn in comparison with a raw bash shell which is quite fast.

olivatooo commented 3 years ago

well you should not use fish as neovim base shell

Only nvim-tree have this performance issue. And using bash does not solve this at all.

kyazdani42 commented 3 years ago

i have these 'performance issues' only running the fish shell, or in huge git directories with lots of changes. Running git commands sometimes take 2/3 seconds even in a raw shell, all you can do is waiting for the refactoring of git running through jobs instead of system function calls.

olivatooo commented 3 years ago

I'm getting this performance problem using bash in a clean git repo :/

tkkcc commented 3 years ago

I have 3 seconds hang on startup and saveing. fish and bash behave same. It's related to git and disappears after I disable the git icon.

let g:nvim_tree_show_icons = {
    \ 'git': 0,
    \ 'folders': 0,
    \ 'files': 0,
    \ 'folder_arrows': 0,
    \ }

So there may be some blocking git function in this plugin?

olivatooo commented 3 years ago

@tkkcc It strangely worked really well here :thinking: thanks, seems to be some blocking git func

kyazdani42 commented 3 years ago

check #549, if this cannot help you, i wont be able too i'm afraid :/ there will be releases that address performance for integrations in the future.

AlphaTechnolog commented 3 years ago
set shell=/bin/bash

Works for me