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

High CPU usage #207

Closed
petobens opened this issue Apr 16, 2014 · 18 comments
Closed

High CPU usage #207

petobens opened this issue Apr 16, 2014 · 18 comments

Comments

@petobens
Copy link
Contributor

I recently noticed that my computer becomes slow when editing files with Vim and I think the problem might be with neocomplete. In the following gif you will see that if I start Vim with a minimal vimrc (attached after the GIF), open that vimrc file and get into insert mode then my CPU usage increases to more than 30%. I'm using Kaoriya GVIM 64-bit version (227 patches) and I build vimproc with MinGW64.
output_ks3di9

This is the minimal vimrc:

set nocompatible

set runtimepath+=~/vimfiles/bundle/neocomplete/
set runtimepath+=~/vimfiles/bundle/vimproc/

let g:neocomplete#enable_at_startup = 1

if !exists('g:neocomplete#keyword_patterns')
    let g:neocomplete#keyword_patterns = {}
endif
let g:neocomplete#keyword_patterns._ = '^\\\?\h\w*$'
let keyword_patterns = {}
let keyword_patterns = {'tex' : '\h\w*:\%(\w*_\w*\)\?'}
call neocomplete#custom#source('buffer', 'keyword_patterns',
        \ keyword_patterns)

I did some profiling which you can download here

@Shougo
Copy link
Owner

Shougo commented Apr 16, 2014

It is feature. Unfortunatelly, in Windows environment, Vim is slow.
I cannot fix it.

@Shougo Shougo closed this as completed Apr 16, 2014
@Shougo
Copy link
Owner

Shougo commented Apr 16, 2014

You can initialize neocomplete when starting.

call neocomplete#initialize()

@petobens
Copy link
Contributor Author

So your recommendation is to have the following in my vimrc?

if neobundle#is_sourced('neocomplete')
    call neocomplete#initialize()
endif

and remove:

let g:neocomplete#enable_at_startup = 1

Or what is the proper way to do it? The docs say:

Note: You should call it in VimEnter autocmd.
User customization for neocomplete must be set before
initialization of neocomplete.

So neocomplete#initialize() should be called at the end of all my necomplete settings? If I call it before my necomplete settings then the cpu usage problem disappears (but my settings are losts) but if I call it at the end then the problem persists.

I'm pretty sure that the problem is not a Vim issue but a neocomplete issue related with the following three lines:

let keyword_patterns = {}
let keyword_patterns = {'tex' : '\h\w*:\%(\w*_\w*\)\?'}
call neocomplete#custom#source('buffer', 'keyword_patterns',
        \ keyword_patterns)

And in particular with the last line (that calls the function): if I remove it
then everything works great (but I need it!). The strange thing I noticed is
that the high CPU usage is present in every filetype except in tex files! I
really hope you can help me. Thanks in advance.

@Shougo
Copy link
Owner

Shougo commented Apr 21, 2014

Sorry, I cannot help you. I think it is initialize feature.
You can check the neocomplete code.
Because, it is open source.

@petobens
Copy link
Contributor Author

I did some more testing and apparently specifying a default pattern seems to fix the problem:

let keyword_patterns = {}
let keyword_patterns = {
        \ 'default' : '\h\w*',
        \ 'tex' : '\h\w*:\%(\w*_\w*\)\?'
        \ }
call neocomplete#custom#source('buffer', 'keyword_patterns',
            \ keyword_patterns)

However I don't understand why this seems to fix it.

@Shougo
Copy link
Owner

Shougo commented Apr 21, 2014

In default, neocomplete uses keyword pattern(\k\+). It is slower than \h\w*.

@petobens
Copy link
Contributor Author

So neocomplete's default pattern for buffer source is \k\+? Where can I see that part of the code? I cannot find it. I ask this because I have a similar setting for the dictionary source:

let keyword_patterns2 = {'tex' : '\\\?\h\w*'}
call neocomplete#custom#source('dictionary', 'keyword_patterns',
        \ keyword_patterns2)

but in the case of dictionary there is no CPU usage problem and no need to specify a default pattern.

@Shougo
Copy link
Owner

Shougo commented Apr 22, 2014

It is from g:neocomplete#keyword_patterns['default'].
I may change this default value.

@petobens
Copy link
Contributor Author

Thanks for the reply. I see that you finally changed the default pattern. My problem however seems to be with neocomplete-source-attribute-keyword_patterns. In the docs it says:

This attribute is optional; if it is not given,
|g:neocomplete#keyword_patterns| is used as the
default value.

However if I don't add default key in keyword_patterns dictionary then my problem appears:

let keyword_patterns = {}
let keyword_patterns = {
        \ 'default' : '\h\w*',
        \ 'tex' : '\h\w*:\%(\w*_\w*\)\?'
        \ }
call neocomplete#custom#source('buffer', 'keyword_patterns',
        \ keyword_patterns)

@Shougo
Copy link
Owner

Shougo commented Apr 22, 2014

However if I don't add default key in keyword_patterns dictionary then my problem appears:

Is it latest version?
I don't know why...

@petobens
Copy link
Contributor Author

I'm using the latest version. If I don't add default key in keyword_patterns dictionary and then call the command :echo neocomplete#get_keyword_pattern('_','buffer') and empty string is returned. Shouldn't that command return \h\w* ? The problem seems to appear when one specifies custom-source-attribute-keyword_patterns because, for instance, if I don't include:

let keyword_patterns2 = {'tex' : '\\\?\h\w*'}
call neocomplete#custom#source('dictionary', 'keyword_patterns',
        \ keyword_patterns2)

then the command :echo neocomplete#get_keyword_pattern('_','dictionary') correctly returns \h\w*. However if I include those lines and call the same command then it returns and empty string.

@Shougo
Copy link
Owner

Shougo commented Apr 22, 2014

OK, I fixed it.

@petobens
Copy link
Contributor Author

Thanks Shougo. I have one more question. If, for instance, if I don't include:

let keyword_patterns2 = {'tex' : '\\\?\h\w*'}
call neocomplete#custom#source('dictionary', 'keyword_patterns',
        \ keyword_patterns2)

then the command :echo neocomplete#get_keyword_pattern('python','dictionary') returns [@]\?\h\w*. However if I include those lines and call the same command now it returns \h\w*. Since I'm not specifying a python key in keyword_patterns2 dictionary why is it returning \h\w* instead of [@]\?\h\w* ?

@Shougo
Copy link
Owner

Shougo commented Apr 23, 2014

Yes, it is feature. Because call neocomplete#custom#source('dictionary', 'keyword_patterns' overwrites default keyword pattern.
You must add patterns manually if needed.
I may add easy way to append default patterns in neocomplete.

@petobens
Copy link
Contributor Author

Ahhh okok. However I think this is not a good feature. I think that neocomplete#custom#source('dictionary', 'keyword_patterns', 'keyword_patterns2') should overwrite patterns only for the filetypes that are defined in the keyword_patterns2 dictionary (in my example only for tex files and leave all other filetypes (such as python) in their default init values).

@petobens
Copy link
Contributor Author

petobens commented May 5, 2014

Hello Shougo. Have you had a chance to read and reconsider what I said in my last comment? Thanks in advance.

@Shougo
Copy link
Owner

Shougo commented May 7, 2014

Yes, I know your comment. I can implement it. But I have not much time.

@petobens
Copy link
Contributor Author

petobens commented May 7, 2014

Thanks! No need to hurry at all. I was just wondering if you had read it.

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

No branches or pull requests

2 participants