Skip to content

Commit 701d22f

Browse files
committed
Defer VCS detection when too many jobs are running
In cases like using `:cfdo`, many buffers may be quickly visited, thus starting lots of VCS detection jobs. This can lead to the (n)vim process having too many open files and all the detection jobs noisily failing. Limit VCS detection to 50 concurrent jobs to mitigate this problem. Since `b:sy` is not being set when detection is deferred, the next visit to the buffer will still run VCS detection. Closes #333
1 parent 8dc2573 commit 701d22f

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

autoload/sy.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ function! sy#start(...) abort
1010
return
1111
endif
1212

13+
if g:signify_detecting > 50
14+
call sy#verbose('Too many detection jobs running, deferring detection')
15+
return
16+
endif
17+
1318
let bufnr = a:0 && has_key(a:1, 'bufnr') ? a:1.bufnr : bufnr('')
1419
let sy = getbufvar(bufnr, 'sy')
1520

autoload/sy/repo.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function! sy#repo#detect(bufnr) abort
77
let sy = getbufvar(a:bufnr, 'sy')
88
for vcs in s:vcs_list
99
let sy.detecting += 1
10+
let g:signify_detecting += 1
1011
call sy#repo#get_diff(a:bufnr, vcs, function('sy#sign#set_signs'))
1112
endfor
1213
endfunction
@@ -130,6 +131,7 @@ function! s:handle_diff(options, exitval) abort
130131
call sy#verbose(printf('Signs already got updated by %s.', sy.updated_by), a:options.vcs)
131132
return
132133
elseif empty(sy.vcs)
134+
let g:signify_detecting -= 1
133135
let sy.detecting -= 1
134136
endif
135137

plugin/signify.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ endif
88

99
let g:loaded_signify = 1
1010
let g:signify_locked = 0
11+
let g:signify_detecting = 0
1112

1213
" Commands {{{1
1314
command! -nargs=0 -bar SignifyList call sy#debug#list_active_buffers()

0 commit comments

Comments
 (0)