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

Startup and startup time problem.. #893

Closed
aksr opened this issue Mar 17, 2014 · 20 comments
Closed

Startup and startup time problem.. #893

aksr opened this issue Mar 17, 2014 · 20 comments

Comments

@aksr
Copy link

aksr commented Mar 17, 2014

I'm using Arch Linux, gvim/vim from the official repository.
Vim with YCM takes too much to startup, even on the empty file.
It hangs with terminal background color and the name of the file at the bottom.
I disabled other plugins, also I tried using new vimrc with only:
syntax on
filetype plugin indent on

No success.
I installed vim-youcompleteme-git from the AUR.
Everything runs fine without YCM.
I noticed a very strange thing: if i resize the terminal (or snap terminal from a tile to a float mode), file immediatelly opens and everything looks fine.
Also if syntax is not enabled automatically, I'm able to open file normally and to use YCM after i enable syntax manually. Meaning--everything is fine even if syntax is enabled if I, as soon as I open the file, "resize" the terminal. Immediatelly after resizing, file is shown.
Same happens with gvim, but "resizing" doesn't help
Similar problem (but without a details):
https://github.com/Valloric/YouCompleteMe/issues/740e
'vim --version' output:
http://privatepaste.com/ed01529bbf
'vim --startuptime $file' output:
http://privatepaste.com/cec6a8a3c9
These two work fine, after I manually enable syntax (which agrees with previously mentioned):
vim -u NORC -N $file
vim -u NONE -N $file
If there's anything I can do to help, please do tell.
Thank you.

@vheon
Copy link
Contributor

vheon commented Mar 17, 2014

I was watching the startup time as well since I'm pretty obsessed about it. The fact that you see the hangs on the terminal background is because the heavy duty is done on VimEnter though the youcompleteme#Enable function which setup all is needed by YCM and start the server. I usually pay 1.5 to 3 seconds for loading YCM on VimEnter depending if the caches are cold or not.

Here is the profiling of the function from cold cache. As you can see the lines that takes more time are: L17 L19 and L30

Now I don't know anything about how python import things and I'm not familiar with the codebase at the point where I could tell you if something is possible to reduce the startup time. So enough talking to me and let's wait for @Valloric :P

@Valloric
Copy link
Member

From the look of @vheon's profile (thanks for that btw), most of the time is spent loading and executing Python code. There's no easy or simple fix for this, and I'm not even sure it's possible to lower this without sacrificing functionality. It would certainly be even longer if the code were VimScript.

I don't see a clear way to progress on this. PRs welcome, as usual, but I doubt anyone could do much here.

Personally, Vim with YCM starts up instantly for me, but both my machine at home and my workstation at work have SSD drives and fast CPUs.

@aksr
Copy link
Author

aksr commented Mar 19, 2014

So, nothing can be done?

@Valloric
Copy link
Member

So, nothing can be done?

I can't see anything that would both work and be worthwhile doing. I'm open to suggestions.

@aksr
Copy link
Author

aksr commented Mar 19, 2014

If it's not a problem, please reopen the issue. That way it'll be not forgotten. Thank you.

@Valloric
Copy link
Member

If it's not a problem, please reopen the issue. That way it'll be not forgotten. Thank you.

I close issues that don't have a clear path ahead to being resolved. Otherwise they just clog up the tracker and still never get addressed (open or closed). The issue can always be reopened.

@KaiSforza
Copy link

I am also having these same issue. Running

vim install.sh -c ':q'

takes almost no time at all, but if I do just a normal

vim install.sh

with YCM enabled, then it will take >2 minutes for the file to load. As soon as I disable YCM, the startup time drops to about 100ms. What's weird is that using ^L to refresh the page causes no changes, however if I change the size of the window (like @aksr), then I do get the same issue. To the untrainted eye, it seems as if vim (particularly YCM) is locking up the screen somewhere. My guess is that it times out fully after about 2 minutes (127 or so seconds) and then just fails. It only seems to happen when there's syntax highlighting and/or filetype plugin and indenting are on in my tests.

The CPU isn't getting maxed, and the load is staying at a normal level.
vim --version: http://paste.kaictl.net/zK2Frn
Timing file: http://paste.kaictl.net/y4B

Do really hope that this issue can be revisited.

EDIT: This happens in a python2 virtualenv, python3 virtualenv, and in no virtualenv at all. Don't know if any of that would help or hurt this.

@Shihira
Copy link

Shihira commented Aug 23, 2014

Can I make YCM not to enable itself automatically when vim starts up?

@vheon
Copy link
Contributor

vheon commented Aug 23, 2014

I personally use vim-plug as my plugin manager and I have this in my vimrc:

function! YCMInstall(info)
  if a:info.status == 'installed'
    !./install.sh --clang-completer
  endif
endfunction
Plug 'Valloric/YouCompleteMe', { 'on': [], 'do': function('YCMInstall') }
let g:ycm_confirm_extra_conf    = 0
let g:ycm_global_ycm_extra_conf = g:dotvim.'/ycm.py'
let g:ycm_extra_conf_vim_data   = ['&filetype']
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_enable_diagnostic_signs = 0
augroup load_ycm
  autocmd!
  autocmd! InsertEnter *
        \ call plug#load('YouCompleteMe')     |
        \ if exists('g:loaded_youcompleteme') |
        \   call youcompleteme#Enable()       |
        \ endif                               |
        \ autocmd! load_ycm
augroup END

Thats because sometimes I start vim just to read some code and not make changes and I don't want to pay the extra cost when not using it. Anyway the first time you enter insert mode you have to load YCM and there's going to be some hang. This is really a hack and I don't know for how long this will be in my vimrc (I guess as soon as I install the SSD on my machine this will go away) and it uses the vim function used on VimEnter for setting it up but is not officially supported so don't count on that to work unlimited ;)

@Shihira
Copy link

Shihira commented Aug 24, 2014

Thanks. vim-plug is somewhat a good alternative of Vundle indeed, buying SSD is out of the question. Adding an option to customize if YCM should auto start can be a robuster solution. I think if vim supports multiple threads, all problems like hang or frozen or something else can get solved. There seems to be such a patch for vim already, but why doesn't vim team merge it directly. Sorry for my complaint.

@ikcalB
Copy link

ikcalB commented Dec 11, 2014

Is there no possibility to call youcompleteme#Enable() in a way, that does not block vim from starting?

Like not having the ycm featuers until that routine is finished, but not blocking anything else!?

@vheon
Copy link
Contributor

vheon commented Dec 11, 2014

@ikcalB No. You're asking for async function call that in vim is not possible.

@ikcalB
Copy link

ikcalB commented Dec 16, 2014

@vheon thanks for clarifying
@Valloric what about an option to change the aucommand event, to load ycm? i.e. on InsertEnter vs VimEnter.

If one could configure the event, and leave that empty, the initialization could be triggered by the user itself
(i.e. only when editing certain filetypes, excuting some layout/setup...)

@vheon
Copy link
Contributor

vheon commented Dec 16, 2014

@ikcalB I did that and if you're experiencing lag on vim startup is much more pleasant to get the lag on vim startup instead of getting lag when you want to write something. Anyway that is how I did that with vim-plug https://github.com/vheon/home/blob/c71c60fcb4d9bf7fb9fe937bc3842735559d36a2/.vim/vimrc#L51-L70

@ikcalB
Copy link

ikcalB commented Dec 16, 2014

@vheon tnx for sharing! I tried using InsertEnter to trigger youcompleteme#Enable() (in YouCompleteMe/plugin/youcompleteme.vim@177 )and I like that one better;
Im also going to use some file-patterns like *{c,cpp,h,hpp} and variables (which indicate that my IDE is enabled, in example)

The only drawback is, that the changes are lost on upgrade. (as plugins are sourced after my vimrc I do not suppose I can overwrite the augroup from there)

@vheon
Copy link
Contributor

vheon commented Dec 16, 2014

What plugin manager are you using? Whatever you are using I highly recommend vim-plug (If you came from Vundle the switch is very easy) and then you can use the setup that I showed you and tweak it for any pattern that you like. Anyway even that is no officially supported by YouCompleteMe so if anything breaks your setup you can blame only yourself :P

@ikcalB
Copy link

ikcalB commented Dec 17, 2014

Using NeoBundle (because I used neocomplete) and quite like it!
For the moment I'm going to stick with what I have - mny tnx!

@vheon
Copy link
Contributor

vheon commented Dec 17, 2014

Using NeoBundle (because I used neocomplete) and quite like it!
For the moment I'm going to stick with what I have - mny tnx!

I don't understand the correlation between the two (except the same author) but if you're comfortable with neobundle there's no need to change and it actually have lots of support for on lazy loading the plugin. I you configure the bundle like this:

NeoBundleLazy 'Valloric/YouCompleteMe', { 'augroup': 'youcompletemeStart' }

Then it know what function to call for the startup and calls them when you will load the bundle though :NeoBundleSource or with the function neobundle#source(...) or through settings like autoload, filetype etc etc. Read the docs for autoload in the neobundle docs.

@ikcalB
Copy link

ikcalB commented Dec 17, 2014

@vheon WOW! Didn't know about that one. Works great, now I can call :NeoBundleSource whenever I want 👍
That should have earned you a beer at least
(btw: when I started to fetch plugins, neocomplete was the first, I liked the idea of NeoBundle, and it was from the same author - was enough reason for me)

& many Thanks again!!

@jabbalaci
Copy link

jabbalaci commented May 14, 2016

I use neovim and I have the same problem, YouCompleteMe increases the load time with about 1 second. However, neovim has async support. I use the vim-plug manager.

Is there a way to load YCM in an async fashion after neovim started?

Update: neovim with vim-plug has a solution for this problem, as explained here: https://github.com/junegunn/vim-plug/wiki/faq#loading-plugins-manually . It gives a concrete example with YCM.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants