Closed cridemichel closed 4 months ago
if one does not want to resort to vim9 scripting, list slicing can used and the function "s:add_highlights_timer" can be modified as follows:
function! s:add_highlights_timer(bufnr, ns, highlights, priority) abort
let lhl = len(a:highlights)
let maxc = g:coc_highlight_maximum_count
if maxc < lhl
let hls = a:highlights[:maxc-1]
let next = a:highlights[maxc:]
else
let hls = a:highlights[:]
let next = []
endif
if bufwinnr(a:bufnr)!=-1 " check if buffer exists
call s:add_highlights(a:bufnr, a:ns, hls, a:priority)
endif
if len(next) && bufwinnr(a:bufnr)!=-1
call timer_start(g:coc_highlight_timer, {->s:add_highlights_timer(a:bufnr, a:ns, next, a:priority)})
endif
endfunction
this solution is as efficient as the previous one and does not require vim9 scripting
PR is welcome!
thanks and please give a look at second fix in #4872 related to error E964, are you able to reproduce it?
Hi, I have just created a pull request to fix #4879 and #4872 (error E964)
Result from CocInfo
VIM VERSION
coc json file
Describe the bug
If semantic tokens are enabled and a large file is opened, vim is very slow, not to say unusuable, until adding highlights is over. For example just after having opened a large file vim "stutters" a lot on scrolling by pressing \<PgUp> or \<PgDown>. In the following I propose also a possible way to fix this issue. If you find it more convenient, I could create a pull request.
Reproduce the bug
1) download the the zip file "files.zip", which you can find below 2) unzip it with
3) open the file "montecarlo.c" which is in the folder "ellipsoid" by using the command:
4) just after the file is opened start scrolling by pressing \<PgDown>
5) vim "stutters" and it is generally slow (even if you try to move around with left/right arrows) until adding highlights is over.
POSSIBLE FIX
After some debugging I found that the cause of this slowdown is due to the for loop in function "s:add_highlights_timer", i.e
hence I decided to resort to vim9 scripting, which is supposed to be much faster. What I suggest is to replace the function "s:add_highlights_timer", i.e.
with
Note that the patch suggested in #4872 has been already applied and a new function, called CreateHlLists(), has been added. This function is written in vim9 scripting language and it turned out to be insanely faster than the legacy solution.
file used to reproduce the bug
files.zip
Minimal vimrc file
Screenshots (optional)
before the fix:
https://github.com/neoclide/coc.nvim/assets/15322138/f3aa9f77-8b4e-45eb-bf61-94b0f393d737
after the fix:
https://github.com/neoclide/coc.nvim/assets/15322138/94e6dcf8-c369-4993-aeee-3298b938a363