abingham / emacs-ycmd

Emacs client for ycmd, the code completion system.
MIT License
384 stars 46 forks source link

Completing with ycmd and company is very slow #451

Open libre-man opened 6 years ago

libre-man commented 6 years ago

Completing C code with with ycmd and company is very slow. I tried to illustrate it with a gif:

I started typing directly after the completion for call appeared however it took a long time before the typed letters actually became visible. If I disable ycmd-mode I do not have this issue.

I'm using spacemacs.

abingham commented 6 years ago

If I disable ycmd-mode I do not have this issue.

Do you mean that when ycmd-mode is disabled completion works perfectly and with good performance? Or that completion doesn't work at all but editing is fast?

What value do you have for ycmd-force-semantic-completion?

libre-man commented 6 years ago

I mean that completion works (but ycmd is not completing, but other sources are) and the performance is good.

I have ycmd-force-semantic-completion set to t as is recommended by spacemacs. Without it I don't get any completions from ycmd it seems.

abingham commented 6 years ago

ycmd-force-semantic-completion is probably the issue. For large enough C++ projects, ycmd's delay to get true semantic completion can be substantial, so that's probably what you're running into. What a lot of people (including myself) do is set ycmd-force-semantic-completion to nil and create a new function for doing semantic completion when we want. You can, of course, make this behavior dependeny on major-mode, etc.

See e.g. the discussion in #183.

libre-man commented 6 years ago

But it is happening for every file in my case. See the example where the file is 10 lines and input already hangs during completion.

abingham commented 6 years ago

It might help if you post any config files that you think are incident: .ycm_extra_conf.py, any emacs configuration, etc. This kind of completion works just fine on many systems, including spacemacs system (like mine).

ptrv commented 6 years ago

The problem is not the file size, rather ycmd is returning completion for the whole namespace you are including, so basically everything from your includes. Also ycmd uses fuzzy matching for candidates, so it returns candidates not only which start with call like in your case but also candidates that contain c, a, l, l non-contiguously.

Usually you want semantic completion after a semantic trigger like . or ->, but I know that for C this not always the case because there are a lot of global function one wants to call and there is no namespaces.

I also think the spacemacs recommendation to set ycmd-force-semantic-completion to t is not optimal.

As @abingham pointed out it's better to have a function and binding to complete with forced semantic completion and leaving identifier based completion for the "as-you-type` case.

libre-man commented 6 years ago

See the example gif I posted. I only included stdlib and stdio, that should be doable right? My elisp config for ycmd is:

(setq ycmd-server-command '("python3" "/home/USER/ycmd/ycmd"))
(setq ycmd-force-semantic-completion t)
(setq-default company-ycmd-insert-arguments
              nil)
(setq-default company-clang-insert-arguments
              nil))

I have not added a custom .ycm_extra_conf.py, the server also starts with the message 2017-10-31 13:14:22,767 - DEBUG - Global extra conf not loaded or no function YcmCorePreload.

I would not really mind that completion takes a bit longer (it is annoying though), but what does really bother me is that typing is blocked while it is completing.

ptrv commented 6 years ago

I would not really mind that completion takes a bit longer (it is annoying though), but what does really bother me is that typing is blocked while it is completing.

@libre-man you can set company-ycmd-request-sync-timeout to 0 in order to have async only completion requests in company-ycmd

I have not added a custom .ycm_extra_conf.py

Spacemacs includes already a global config file which sets up basic includes

libre-man commented 6 years ago

When setting company-ycmd-request-sync-timeout to 0 smaller files work a lot better. However when opening a small project (that does include larger projects such as libcheck) the lag in typing reappears: . You can see that the push appears very quickly, that is not because I typed it really fast but because of the mentioned lag.

About the config, I haven't changed anything about spacemacs in that regard, but I can't find a file named .ycm_extra_conf.py anywhere on my computer using locate.

ptrv commented 6 years ago

Could you please post a small example so we are able to reproduce it?

libre-man commented 6 years ago

Sure, I'll try to do that later tonight.

johndebord commented 6 years ago

Related, but I suppose still relevant in this thread; I put the following in my init file: (set-variable 'ycmd-force-semantic-completion nil) (setq company-ycmd-request-sync-timeout 0)

Is there anything else I can do to make the text editing more seamless and smooth?

I'm really not a big fan of feeling like I'm typing on a remote server based in China.