-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add g:ycm_start_autocmd option #2454
Conversation
Profiling with `vim --startuptime` shows that YCM is responsible for about 250ms of the overall 500ms that Vim spends starting up on my machine. By switching from "VimEnter" to "CursorHold,CursorHoldI" as a trigger for calling `youcompleteme#Enable`, we get almost all of that back, leading to an approximately 50% speed-up and a very perceptible improvement in responsiveness. The trade-off here is that YCM won't get fully initialized until Vim has been idle for `'updatetime'` seconds (2s in my set-up, which apparently YCM itself sets; before YCM runs though, the default of 4s is probably active). As not everybody may like this trade-off, I've made all this configurable via an option.
Corresponding pull request for the YCM change is: ycm-core/YouCompleteMe#2454 I made the PR against the current `master` branch, but the commit I am running against here is based on top of the `wincent` branch in my fork, which is older (over a year older at this point, and probably several hundred commits) and which I haven't seen a compelling reason to update yet: https://github.com/wincent/YouCompleteMe/commit/ac1df6701831f8215effa228ef4d71f077d99653 Quoting the message here for context: > Profiling with `vim --startuptime` shows that YCM is responsible for > about 250ms of the overall 500ms that Vim spends starting up on my > machine. By switching from "VimEnter" to "CursorHold,CursorHoldI" as a > trigger for calling `youcompleteme#Enable`, we get almost all of that > back, leading to an approximately 50% speed-up and a very perceptible > improvement in responsiveness. > > The trade-off here is that YCM won't get fully initialized until Vim has > been idle for `'updatetime'` seconds (2s in my set-up, which apparently > YCM itself sets; before YCM runs though, the default of 4s is probably > active). As not everybody may like this trade-off, I've made all this > configurable via an option. * roles/dotfiles/files/.vim/pack/bundle/start/YouCompleteMe 3429617...ac1df67 (1): > Add g:ycm_start_autocmd option
Current coverage is 84.44% (diff: 100%)@@ master #2454 diff @@
==========================================
Files 17 17
Lines 1903 1903
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
Hits 1607 1607
Misses 296 296
Partials 0 0
|
Thanks for sending a PR! I'm not necessarily against the change you're making, but I am against exposing it as an option. We already have waaaay too many of them and are extremely wary about adding more. This change, if it works well, should just be something we do for everyone. Given that, it's a fairly scary change that has the potential to break stuff. So we need to be careful here. What possible drawbacks do you see of doing this for everyone? Having YCM be unavailable for the first 2 seconds might be worth the startup gains... @micbou @puremourning @vheon Thoughts? |
One thing to note is that it won't be 2 seconds but 4 seconds given the default |
What we're ultimately trying to do is start YCM startup asynchronously. I know latest Vim has some async APIs, so we might want to detect the presence of these and use them for faster startup. If they're not there, go with the old blocking approach. The it becomes a "simple" issue of upgrading your Vim to get better startup perf. The benefit is that we wouldn't have any artificial delay from updatetime on when startup actually triggers. |
I'm not a big fan of this change. Not for the change itself but rather because if we start doing this kind of changes I'm afraid that users with slightly different needs will ask to tweak this again, leading to more user options for "not so used functionalities". Instead what I would prefer is to let the user decide when to load YCM and be done with it. Since #2084 YCM is ready to be lazy-loaded. This means that for this specific use case (load YCM on the first Plug 'Valloric/YouCompleteMe', { 'on': [] }
augroup load_ycm
autocmd!
autocmd CursorHold, CursorHoldI * call plug#load('YouCompleteMe')
\ | autocmd! load_ycm
augroup END or a user with the latest vim can use the augroup load_ycm
autocmd!
autocmd CursorHold, CursorHoldI * :packadd YouCompleteMe
\ | autocmd! load_ycm
augroup END
For me this is the proper way to solve the startup problem. PS: @wincent I'm a fan of your vim screencasts, keep'em coming 😛 👍 |
Good points, @vheon. The reason I made this PR is because there is clearly an intent in the implementation to move loading out of the critical startup path by default, requiring no additional action from the user. (I ended up adding an option only because it constituted a behavior change and so I thought it might make it more likely to be accepted.) I'm happy for this to be closed, but I think perhaps the entire
(not a real patch; edited in the browser.) |
Could you elaborate what that would buy us? @vheon I did forget about the packadd feature, thanks for pointing that out. I also agree with @wincent's point that we should probably be doing some sort of async loading by default if we can get away with it without impacting functionality. |
The presence of the
Are all misleading, because they don't have the desired effect. I think you should either make deferred loading work automatically, or document how the user can achieve it (ie. via |
Actually there was a reason for this which was that had to be sure to be executed after Ultisnips and with |
I can't really disagree with this. :) |
@wincent so at this point we either close this or if you want (and have the time) you can change this to the "patch" you proposed at #2454 (comment), otherwise I'll do it without problem 👍 If you decide to change this and you want to change the docs, don't touch the |
No lazy # PR Prelude - [x] I have read and understood YCM's [CONTRIBUTING][cont] document. - [x] I have read and understood YCM's [CODE_OF_CONDUCT][code] document. - [x] I have included tests for the changes in my PR. If not, I have included a rationale for why I haven't. - [x] **I understand my PR may be closed if it becomes obvious I didn't actually perform all of these steps.** # Why this change is necessary and useful See prior version of this PR (#2454) for more discussion. [cont]: https://github.com/Valloric/YouCompleteMe/blob/master/CONTRIBUTING.md [code]: https://github.com/Valloric/YouCompleteMe/blob/master/CODE_OF_CONDUCT.md <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2473) <!-- Reviewable:end -->
PR Prelude
Thank you for working on YCM! :)
Please complete these steps and check these boxes (by putting an
x
insidethe brackets) before filing your PR:
rationale for why I haven't.
actually perform all of these steps.
Why this change is necessary and useful
Profiling with
vim --startuptime
shows that YCM is responsible for about 250ms of the overall 500ms that Vim spends starting up on my machine. By switching from "VimEnter" to "CursorHold,CursorHoldI" as a trigger for callingyoucompleteme#Enable
, we get almost all of that back, leading to an approximately 50% speed-up and a very perceptible improvement in responsiveness.The trade-off here is that YCM won't get fully initialized until Vim has been idle for
'updatetime'
seconds (2s in my set-up, which apparently YCM itself sets; before YCM runs though, the default of 4s is probably active). As not everybody may like this trade-off, I've made all this configurable via an option.Test plan: Manually tested with
--startuptime
and the settings shown in the documentation (no automated tests yet because testing VimScript changes automatically is hard, like it says in theCONTRIBUTING
doc; wanting some feedback on whether this would be the sort of thing that you'd want to include before I go further with it).This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)