lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.42k stars 389 forks source link

Really heavy cpu load on ncm2 completion #1279

Closed choreutes closed 5 years ago

choreutes commented 5 years ago

Hey,

I'm not even sure if this is the right place to go to, but since I have no better guess either here I am: I have worked on a bigger LaTeX project (master thesis) during the last several weeks and it was mostly a very pleasant experience (great plugin!). The only thing that kept bugging me was that sometimes the autocompletion would lag really hard.

A short look into htop revealed that the ncm2_core thread was putting a solid 100% load on one of my cpu cores constantly in those situations. As you might have guessed by now, I'm using ncm2 as my completion manager, so this could as well be ncm2's fault and not yours. I'm not very experienced at debugging (n)vim plugins using yet another plugin and I don't know about any logs that might be helpful, so I'm not gonna blame anyone. I just have this feeling that not quite as many people would use a completion manager that constantly eats away one of their cpu cores, so I'm turning to you first. I'm grateful for hints in any other direction if you have any!

I'm using neovim 0.3.1 on Arch Linux with vim-plug as a plugin manager and my config is pretty straight from the documentation. Just in case I did any stupid copy-paste error:

Plug 'roxma/nvim-yarp', { 'do': ':UpdateRemotePlugins' }
Plug 'ncm2/ncm2', { 'do': ':UpdateRemotePlugins' }
Plug 'ncm2/ncm2-path'
Plug 'autozimu/LanguageClient-neovim', { 'do': ':UpdateRemotePlugins' }
Plug 'lervag/vimtex'

set completeopt=menuone,noselect,noinsert

augroup completion_setup
  autocmd!
  autocmd BufEnter * call ncm2#enable_for_buffer()
  autocmd Filetype tex call ncm2#register_source({
      \ 'name': 'vimtex',
      \ 'priority': 8,
      \ 'scope': [ 'tex' ],
      \ 'mark': 'tex',
      \ 'word_pattern': '\w+',
      \ 'complete_pattern': g:vimtex#re#ncm2,
      \ 'on_complete': [ 'ncm2#on_complete#omni', 'vimtex#complete#omnifunc' ]
      \})
augroup END

Sadly I also don't really know how to reproduce this behaviour as it only happens in some situations. The only hunch I have at the moment is that it might have something to do with me hopping though different subfiles via the TOC quite frequently but this might also be just some random stupid thought.

Once again, any help is appreciated!

lervag commented 5 years ago

I'm really sorry to say that I don't really know a very good way to debug this. One possibility is to try to use deoplete as an alternative to ncm2 for some time. I use deoplete now, and I use the following settings, approximately:

" ...
Plug 'Shougo/deoplete.nvim',
      \ has('nvim') ? { 'do': ':UpdateRemotePlugins' } : {}
" ...
call plug#end()

let g:deoplete#enable_at_startup = 1

call deoplete#custom#option('smart_case', v:true)
call deoplete#custom#option('ignore_sources', {
      \ '_': ['around'],
      \})

call deoplete#custom#source('_', 'disabled_syntaxes', ['Comment', 'String'])

call deoplete#custom#var('omni', 'input_patterns', {
      \ 'tex' : g:vimtex#re#deoplete,
      \})

inoremap <expr><c-h>   deoplete#smart_close_popup() . "\<c-h>"
inoremap <expr><bs>    deoplete#smart_close_popup() . "\<c-h>"
inoremap <expr><cr>    pumvisible() ? "\<c-y>\<cr>" : "\<cr>"
inoremap <expr><tab>   pumvisible() ? "\<c-n>" : "\<tab>"
inoremap <expr><s-tab> pumvisible() ? "\<c-p>" : "\<s-tab>"

I've used ncm2, which mostly works well. I can't really decide which framework I like the best. But in any case, if changing to deoplete also solves your issue, then it is an indication that your problem is not with vimtex.

With that said, it would also be helpful to know which "context" you are completing when you recognize the slowdowns. As you might know, vimtex provides a lot of different types of completion.

choreutes commented 5 years ago

Thanks for your quick reply! :)

Of course I figured that this is probably difficult to debug. I just thought I should let you know anyway, and maybe someone else has had similar problems.

The context I noticed the lag most of the time was when I tried to complete a citation from my biblatex file. But the cpu load remained even when I deleted the possible completion and stopped typing altogether. That’s why I thought it might be something a little more general.

Regarding the context of the completion: In the documentation you mention the possibility to register different types of completions seperately to ncm2. Do you think this might change anything? What is the difference between the two registrations, anyway? I think it just says that the separate registration is a little more “lenient” which doesn't tell me too much.

In any case I might give deoplete a try and also ask the ncm2 guys if they have any additional thoughts. Thanks again for your support!

lervag commented 5 years ago

In the documentation you mention the possibility to register different types of completions seperately to ncm2. Do you think this might change anything?

No, I don't really think it should have anything to do with this issue. But I don't know, you could try and see if it fixes things.

What is the difference between the two registrations, anyway?

The more complex configuration is more "specific". The simple configuration will call the omnicomplete function more often and with a more generic tag "[tex]", while the more complex will use more specific tags in the specific contexts, as well as apply different matchers (read the ncm docs to learn more about this).