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

Allow toggling "watch_gitdir" or dynamically changing watch interval #822

Closed
mars90226 opened this issue Jun 19, 2023 · 7 comments
Closed
Labels
enhancement New feature or request

Comments

@mars90226
Copy link

mars90226 commented Jun 19, 2023

Is your feature request related to a problem? Please describe.
I work for the project that consisted of many small git repos. Usually I open each neovim instance for each git repo and switch between them. I would like to avoid or lower the CPU usage of gitsigns.nvim "watch_gitdir" in background neovim instances.

Describe the solution you'd like
A command to toggle "watch_gitdir" or change "watch_gitdir" interval.

Describe alternatives you've considered
Automatically disable "watch_gitdir" in background neovim instances.

Additional context
I've tried to implement this in my config by trying to change directory to non-git directory on FocusLost and changing back on FocusGained. But the debounced update_cwd_head function seems not called when triggered this way.

@mars90226 mars90226 added the enhancement New feature or request label Jun 19, 2023
@lewis6991
Copy link
Owner

Can't you just disable config.watch_gitdir?

I'm really not interested in adding a dynamic. Having a poll object for each open buffer shouldn't use much CPU.

@mars90226
Copy link
Author

Well, the watcher does create many epoll_pwait()s on my machine and raise the load averages quite a lot if I open many neovim instances. Maybe I just raise the interval to 60 seconds to workaround this. Thanks anyway!

@mars90226 mars90226 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2023
@lewis6991
Copy link
Owner

Are you talking about the cwd_watcher or the gitdir watcher? The gitdir_watcher can be disabled.

@mars90226
Copy link
Author

Oops, I think I may traced the wrong code 😅 I tried to reduce the epoll_pwait() numbers and grepped new_fs_poll() to find out. I found that gitsigns.nvim cwd_watcher is using the new_fs_poll() and think it's the culprit. But it's actually the gitdir_watcher that cause all the epoll_pwait()?

@mars90226
Copy link
Author

I know I can disable watch_gitdir with enable = false. But I want to enable it when I'm actually using the neovim (it's in the foreground).

@lewis6991
Copy link
Owner

lewis6991 commented Jun 19, 2023

There are a few improvements we can make:

  • Use fs_events instead of polling. I've started this in feat(watcher): move from libuv poll to file event watcher #660
  • Share watchers across buffers apart from the same repository. Currently, each buffer gets its own watcher.
  • Stop the watchers when nvim is backgrounded. Or better: stop watchers after the first trigger when nvim is backgrouned since any subsequent callbacks aren't doing anything useful.

I've raised #823 to track this. I don't plan on working on this soon, so PR's would be welcome if you're feeling up to it.

@mars90226
Copy link
Author

Thanks! I'm not familiar with libuv, but I can try stopping watchers when nvim is backgrounded when I have free time.

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

No branches or pull requests

2 participants