neoclide / coc.nvim

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Other
24.33k stars 956 forks source link

A coc-nvim function takes between 0.5 and 1 second to complete (synchronously), causing lag #3179

Closed starptr closed 3 years ago

starptr commented 3 years ago

Result from CocInfo

## versions

vim version: NVIM v0.5.0-dev+1449-gbdf3df402
node version: v14.17.0
coc.nvim version: 0.0.80-b427b2ccfa
coc.nvim directory: /home/yuto/.vim/plugged/coc.nvim
term: WezTerm
platform: linux

## Log of coc.nvim

2021-06-28T21:44:26.787 INFO (pid:3303) [services] - registered service "diagnostic-languageserver"
2021-06-28T21:44:26.926 WARN (pid:3303) [attach] - Plugin not ready when received "highlight" []
2021-06-28T21:44:27.111 INFO (pid:3303) [plugin] - coc.nvim 0.0.80-b427b2ccfa initialized with node: v14.17.0 after 845ms
2021-06-28T21:44:27.343 INFO (pid:3303) [attach] - receive notification: highlight []
2021-06-28T21:44:30.841 INFO (pid:3303) [attach] - receive notification: highlight []
2021-06-28T21:44:31.321 INFO (pid:3303) [attach] - receive notification: highlight []
2021-06-28T21:44:33.100 INFO (pid:3303) [attach] - receive notification: highlight []
2021-06-28T21:47:45.593 INFO (pid:3303) [attach] - receive notification: showInfo []

Describe the bug

By performing the profiling strategy described in this FAQ, I consistently catch the <SNR>32_request() function taking anywhere between 0.5 and 1 second to complete. I suspect this is causing lag.

FUNCTION  <SNR>32_request()
    Defined: ~/.vim/plugged/coc.nvim/autoload/coc/client.vim:154
Called 9 times
Total time:   0.584666
 Self time:   0.583493

count  total (s)   self (s)
    9   0.000111   0.000068   let channel = coc#client#get_channel(self)
    9              0.000019   if empty(channel) | return '' | endif
    9              0.000007   try
    9              0.000006     if s:is_vim
                                  let res = ch_evalexpr(channel, [a:method, a:args], {'timeout': 60 * 1000})
                                  if type(res) == 1 && res ==# ''
                                    throw 'request '.a:method. ' '.string(a:args).' timeout after 60s'
                                  endif
                                  let [l:errmsg, res] =  res
                                  if !empty(l:errmsg)
                                    throw l:errmsg
                                  else
                                    return res
                                  endif
    9              0.000004     else
    9   0.584092   0.582962       return call('rpcrequest', [channel, a:method] + a:args)
                                endif
                              catch /.*/
                                if v:exception =~# 'E475'
                                  if get(g:, 'coc_vim_leaving', 0) | return | endif
                                  echohl Error | echom '['.self.name.'] server connection lost' | echohl None
                                  let name = self.name
                                  call s:on_exit(name, 0)
                                  execute 'silent do User ConnectionLost'.toupper(name[0]).name[1:]
                                elseif v:exception =~# 'E12'
                                  " neovim's bug, ignore it
                                else
                                  echohl Error | echo 'Error on request ('.a:method.'): '.v:exception | echohl None
                                endif
    9              0.000012   endtry

Reproduce the bug

I couldn't get coc-nvim to work without vim-plug:

set nocompatible
"set runtimepath^=~/.vim/plugged/coc.nvim/plugin/
"runtime coc.vim
call plug#begin('~/.vim/plugged')
    Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
filetype plugin indent on
syntax on
set hidden

Unfortunately, it is not consistent, but I did manage to get >1 second self-time confirmed in the same function at the same line with the profile.

chemzqm commented 3 years ago

You have to provide :CocInfo after you get that lag and minimal vimrc to reproduce, also checkout :h CocActionAsync()

chemzqm commented 3 years ago

There're some logs added to trace this kind of issue, try upgrade coc.nvim and upload the log after you get lag.