Skip to content

Hangs on saving #389

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

Closed
dvogt23 opened this issue May 20, 2021 · 25 comments
Closed

Hangs on saving #389

dvogt23 opened this issue May 20, 2021 · 25 comments

Comments

@dvogt23
Copy link

dvogt23 commented May 20, 2021

After install nvim-tree nvim hangs on saving 🤔 somtime just 2sec, sometime more ...
nvim-tree

any idea? whats info need for debug?

@kyazdani42
Copy link
Member

i'm really not sure what this is about. Are you sure this comes from nvim-tree ? Your tree is not even opened so this seems strange to me

@dvogt23
Copy link
Author

dvogt23 commented May 21, 2021

Yes, just after the include with the packer this happens 😞 so unfortunately yes ... after dropping this plugin, everything looks fine. Can I help with some additional info?

@kyazdani42
Copy link
Member

hm, maybe a minimal init so i can reproduce ? and your neovim version :)

@dvogt23
Copy link
Author

dvogt23 commented May 21, 2021

sure thing :) nvim NVIM v0.5.0-dev+nightly-105-g66f9dd3c6

tree_cb = require'nvim-tree.config'.nvim_tree_callback
vim.g.nvim_tree_bindings = {
  ["<CR>"]           = tree_cb("edit"),
  ["<C-CR>"]          = tree_cb("cd"),
  ["<C-v>"]          = tree_cb("vsplit"),
  ["<C-x>"]          = tree_cb("split"),
  ["<C-t>"]          = tree_cb("tabnew"),
  ["<BS>"]           = tree_cb("close_node"),
  ["<S-CR>"]         = tree_cb("close_node"),
  ["<Tab>"]          = tree_cb("preview"),
  ["I"]              = tree_cb("toggle_ignored"),
  ["H"]              = tree_cb("toggle_dotfiles"),
  ["R"]              = tree_cb("refresh"),
  ["a"]              = tree_cb("create"),
  ["d"]              = tree_cb("remove"),
  ["r"]              = tree_cb("rename"),
  ["<C-r>"]          = tree_cb("full_rename"),
  ["x"]              = tree_cb("cut"),
  ["c"]              = tree_cb("copy"),
  ["p"]              = tree_cb("paste"),
  ["-"]              = tree_cb("dir_up"),
  ["q"]              = tree_cb("close"),
}

vim.g.nvim_tree_side = 'left'
vim.g.nvim_tree_width = 30
vim.g.nvim_tree_ignore = {
  '.git', 'node_modules', 'dist', '.cache'
}
vim.g.nvim_tree_auto_open = 0
vim.g.nvim_tree_auto_close = 0
vim.g.nvim_tree_follow = 1
vim.g.nvim_tree_indent_markers = 1
vim.g.nvim_tree_hide_dotfiles = 1
vim.g.nvim_tree_git_hl = 1
vim.g.nvim_tree_root_folder_modifier = ':~'
vim.g.nvim_tree_tab_open = 0
vim.g.nvim_tree_show_icons = {git = 0, folders = 1, files = 0}

vim.g.nvim_tree_icons = {
  symlink = '',

  git = {
    unstaged = "",
    staged = "",
    unmerged = "",
    renamed = "",
    untracked = ""
  },

  -- folder = {default = "", open = " "}
  folder = {
   default = "",
   open = "",
   empty = "",
   empty_open = "",
   symlink = "",
   symlink_open = "",
  },
}

@kyazdani42
Copy link
Member

i cannot reproduce the lag :/ seems weird that this is nvim-tree related, could you disable the ligne 15 in tree.vim and tell me if the lag is still here ? If not, this cannot be nvim tree related.

@Shatur
Copy link

Shatur commented May 25, 2021

Same here, happens when git integration is enabled. Try to disable it (vim.g.nvim_tree_git_hl = 0).

@dvogt23
Copy link
Author

dvogt23 commented May 25, 2021

Same here, happens when git integration is enabled. Try to disable it (vim.g.nvim_tree_git_hl = 0).

thanks! Thats it ... thanks @kyazdani42 for investigation and this great plugin 🥇 🙏🏾

@dvogt23 dvogt23 closed this as completed May 25, 2021
@kyazdani42
Copy link
Member

git integration could indeed slow down the plugin as it's using cli commands (and i'm not sure how fast cli commands happen but they are usually slower than libraries). If something like https://github.com/libgit2/luagit2 can be integrated at some point that would be nicer i suppose

@Samyak2
Copy link

Samyak2 commented May 27, 2021

I have the same issue with everything updated to the latest versions. Saving a file pauses everything for 1-2s. Opening neovim is slow too (~1.5s), but it's not captured by --startuptime. Removing nvim-tree fixes the slowdowns.

Also worth mentioning that this happens when opening neovim inside a large repository (even without opening a file). Opening neovim in my home dir or my config dir does not show the same behaviour.

vim.g.nvim_tree_git_hl = 0

This did not work for me, it was already disabled. Is there any other setup parameter that makes use of CLI commands?

I'll try making a minimal reproducible config. I'm on NVIM v0.5.0-dev+1357-g192f89ea1

@Shatur
Copy link

Shatur commented May 27, 2021

This did not work for me, it was already disabled. Is there any other setup parameter that makes use of CLI commands?

There is also nvim_tree_show_icons, you should disable git.

@Samyak2
Copy link

Samyak2 commented May 27, 2021

That fixed the delay on save. Thank you!

Although the lag on startup still exists.

@kyazdani42
Copy link
Member

lag on startup i cannot reproduce, but it might be related to you shell. if you set shell=/some/shell/without/config, does the lag still exists ?

@Samyak2
Copy link

Samyak2 commented May 28, 2021

I tried setting shell to /usr/bin/bash --noprofile --norc, it did not change the startup time in any way. Takes nearly ~10s inside a large repo.

Should I open a new issue for this?

@Samyak2
Copy link

Samyak2 commented May 28, 2021

I also tried opening neovim from a fresh shell with all environment variables reset (env -i bash --noprofile --norc), the lag still exists.

@kyazdani42
Copy link
Member

set the shell through nvim maybe ? I'm really not sure how this plugin could affect 10seconds of startup time, this has been discussed many times and it was never this fault. Been using this for a long time, when i started writing it and never experienced this.
Maybe checkout the perf branch (check in the pull requests) and do some debugging because i'm not sure how a simple lua startup could take so much time. Do you have a low performance computer ?

@Samyak2
Copy link

Samyak2 commented May 28, 2021

set the shell through nvim maybe ?

Yes, I that was the first thing I tried. I set vim.o.shell in my config and confirmed it inside nvim with set shell?

Maybe checkout the perf branch (check in the pull requests)

I will try that.

and do some debugging

I've never debugged/profiled lua in nvim before. I'll look it up, but if you know any specific references it would be helpful.

Do you have a low performance computer ?

My laptop has 4 cores with HT (8 threads) (specifically i5-8265U), 16GB RAM and SSDs (no HDDs). I don't think it's a hardware performance issue.


Thank you for writing this plugin ❤️, I will try my best to debug this issue.

@Samyak2
Copy link

Samyak2 commented May 28, 2021

I tried the helper/performance-debugging branch and this is what I get in /tmp/nvim-tree-perf.log.

executed set_index_and_redraw in 0.002681ms
executed init in 6845.818954ms
executed set_index_and_redraw in 0.002466ms
executed init in 6928.80124ms

Looks like init does some git operations and calls stat on each file. Or this only for the top level files/directories? I don't know enough about the codebase to understand this yet.


Another thing I noticed is that in a directory with 111,188 files/directories, I see the ~8s startup time. But on a similar (almost exactly same) directory structure with 106,147 files/directories there is no slow down. No slow down at all, time nvims -c ":q" shows times similar to when the plugin is not installed. Here are the results from that directory

executed set_index_and_redraw in 0.002902ms
executed init in 18.426288ms
executed set_index_and_redraw in 0.002482ms
executed init in 17.991625ms

What's even more puzzling is that these two directories are branches of the same repo, checked out at different directories.

I will try profiling this further, apologize for all the pings 🙇


Update: I have identified this line to be the cause of it:

https://github.com/kyazdani42/nvim-tree.lua/blob/86b7b2c9c4fca36dfa4c04963c6f2ed05ca87961/lua/nvim-tree/lib.lua#L29


Update 2: I have further identified this to be the cause of it:

https://github.com/kyazdani42/nvim-tree.lua/blob/86b7b2c9c4fca36dfa4c04963c6f2ed05ca87961/lua/nvim-tree/git.lua#L93-L95


Update 3:

https://github.com/kyazdani42/nvim-tree.lua/blob/86b7b2c9c4fca36dfa4c04963c6f2ed05ca87961/lua/nvim-tree/git.lua#L82

@Samyak2
Copy link

Samyak2 commented May 28, 2021

Aha! I found the issue. There were many, many untracked files - 395,986 of them! (I blame node_modules). Showing all of them even using the git command directly (git status --porcelain=v1 --ignored=matching -u) takes >7s.

Is there a reason nvim-tree needs to get the list of all untracked files and then loop through all of them? Looks like it's just to check for gitignored files. Is there a configuration parameter to disable this? If not, would this be a useful addition? (I would like to contribute if so).

@kyazdani42
Copy link
Member

hi @Samyak2, you debugged perfectly, thanks a lot :)
well indeed 400K files to track with git is slow. you could vim.g.nvim_tree_gitignore = 0 in your init.lua to avoid ignoring files from gitignore but i'm not sure this is the issue here.
I need to get the whole list of the git statuses to apply git informations in the tree, of course if you have 400K changes it will slow down considerably.
Maybe just try to ignore these files ?

@Samyak2
Copy link

Samyak2 commented May 31, 2021

Yes, ignoring or deleting these files is a good solution.

But, I was wondering if it's possible to disable all git operations in nvim-tree.

I have the following set in my config:

vim.g.nvim_tree_git_hl = 0
vim.g.nvim_tree_gitignore = 0
vim.g.nvim_tree_show_icons = {
    git = 0,
    folders = 1,
    files = 1,
 }

and no git information shows up in the tree. So, is that git information really needed? I can send a PR to fix this if it's not needed.

@kyazdani42
Copy link
Member

i don't think so, if you can send a PR to fix it it'll be very welcome :)

@saihnii4 saihnii4 mentioned this issue Jul 20, 2021
@ChrisTsou
Copy link

ChrisTsou commented Jul 23, 2021

I stumbled in this today, you should definitely set git hl and git icons off by default.

@kyazdani42
Copy link
Member

I'm not sure because I'm pretty sure most people use this. what i should do though is rewrite the git module because I can make it fast.

@splitDEV
Copy link

splitDEV commented Aug 2, 2021

Hi, thank you for your time and effort for writing and maintaining this great plugin 😄

I have basically the same issue (hanging on startup/buffer save/opening fugitive for >3s) when editing my dotfiles and figured out it relates to git as well:
I use a bare git repository for storing my dotfiles and I guess that you try to find the git root directory and end up in $HOME which has of course many untracked files (intentionally). I configured my dotfiles git in $HOME to status.showUntrackedFiles=false but I guess you try to find all untracked files in $HOME anyway?

Just a use case to take into account if you happen to rewrite the git module? 🙃
Because right now nvim-tree.lua is more or less unusable for me 😞

@kyazdani42
Copy link
Member

#549
i'm working on a refactoring of git to make this more configurable

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

No branches or pull requests

6 participants