nvim-lualine / lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
MIT License
5.93k stars 461 forks source link

Bug: Large performance degradation when navigating newly-opened files in sshfs-mounted remote directories #715

Open shaun-mathew opened 2 years ago

shaun-mathew commented 2 years ago

Self Checks

How to reproduce the problem

  1. Mount remote directory using sshfs -o allow_other user@remote:/path/ /path/to/local/mountpoint
  2. CD to local mount point
  3. Open an existing file with neovim. There may be some performance degradation.
  4. Open another existing using :e other_file. Navigation in new file is extremely laggy.

Expected behaviour

Neovim does not lag when opening files in remote-mounted directory.

Actual behaviour

Extreme degradation of performance when navigating through newly opened files in remote-mounted directory

Minimal config to reproduce the issue


call plug#begin("~/lualine_test/.local/share/nvim/plugged")
Plug 'nvim-lualine/lualine.nvim'

call plug#end()

lua << END

require'lualine'.setup {

}

END

Aditional information

Tried with another statusline plugin (feline.nvim) and the issue doesn't appear when using said statusline plugin.

shadmansaleh commented 2 years ago

I don't really use sshfs myself. Can you check which component is causing the issue ?

shaun-mathew commented 2 years ago

Sure, I'll take a look. Do you have a lua profiler that you use for debugging? I'm getting errors trying to run plenary.profile (https://github.com/nvim-lua/plenary.nvim#plenaryprofile)

shaun-mathew commented 2 years ago

Seems like disabling both the filetype component and the branch component stops the lag

shadmansaleh commented 2 years ago

It's probably just the branch component. When a new file is opened it tries to find git root for that file . This can cause plenty of io operations to climb up the directory tree and to check for .git folder . I think that's just slow for sshfs as the io operations relays on servers reply. Not sure what to do about this though without finding git root we can't show the git branch .

shaun-mathew commented 2 years ago

Yeah, that's what I figured. It appears that the directory I'm in doesn't have a .git directory, so it appears that the branch component periodically performs this recursive check for a .git directory to see if one does exist and because of server latency the UI slows down. I did add a cache entry to the git_dir_cache entry table when the git_dir is nil which "fixes" the issue. Unfortunately, this would have the added side-effect of not properly updating lualine if a git init is called after neovim is open. Is it possible to update the branch component less frequently, since it would then be possible to clear the cache entry in the case that the git_dir is nil?

With regard to the filetype component, adding nvim-web-devicons as a requirement and using require instead of pcall require in the apply_icon() function fixes that issue. For some reason, a protected call makes it lag when the nvim-web-devicons plugin is not installed.

shadmansaleh commented 2 years ago

We can eventually make the fs calls async so it doesn't block ui. For now if you have other git plugins like gitsigns, vim-fugitive ... you can show the branch status from those plugins instead of the branch component. For example like this

If pcall is removed lualine will throw an error if nvim-webdevicons isn't installed . If you don't want icons in filetype component you can set icons_enabled option in filetype component to false that should fix the delay I believe.


lualine_x = {
  {'filetype', icons_enabled = false}
}