abingham / emacs-ycmd

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

Typing hangs when code completion takes a while #163

Open r4nt opened 9 years ago

r4nt commented 9 years ago

I work in Clang, which has really large translation units. Apparently code completion takes a while there, and while that is on, I cannot type any more (I use instant completion). Is that a problem in company-mode or emacs-ycmd?

r4nt commented 9 years ago

Repro: $ for i in $(seq 20000) ; do echo "int f$i() {}"; done > t.cc $ emacs -nw t.cc Go anywhere and start typing a (takes a while before "a" shows up) b (takes a while before "b" shows up) ...

I also discussed this with company-mode: https://github.com/company-mode/company-mode/issues/325

r4nt commented 9 years ago

Some data from @dgutov

Well, at least for this example I get this ELP output: json-encode 49 40.373922852 0.8239576092 json-encode-list 12 30.454752527 2.5378960439 json-encode-alist 9 30.45463016 3.3838477955 ycmd-get-completions 3 10.515761361 3.5052537869 ycmd--request 5 10.504717434 2.1009434868 json-encode-string 30 9.9188939140 0.3306297971 js on-encode-char 927259 6.9621825919 7.508...e-06 json-encode-char0 927259 1.1932534209 1.286...e-06 ycmd-request-deferred 5 0.263508196 0.0527016392 ycmd-request 5 0.263467947 0.0526935894 ycmd-request--curl 5 0.263334671 0.0526669342 json-join 9 0.1421685389 0.0157965043 ycmd--standard-content-with-extras 3 0.0126280259 0.004209342 ycmd--standard-content 3 0.0126114730 0.0042038243 json-read 90 0.0070623759 7.847...e-05 ... That's 0.8sec, on average, spent in json-encode. Try evaluating (length (json-encode (ycmd--standard-> content))) in this buffer and see how long it takes (~3 seconds 0.5 sec for me). This is the data that has > to be generated before making the request.

So, the big file size is definitely a factor here. Do you have an example where the current file isn't huge? I guess it's allowed to include a huge header, but then ycmd needs some file with project options I'm not familiar with.

dgutov commented 9 years ago

So, this should be much improved in the current Emacs master.

If having the same in older Emacs versions, you could version-conditionally advise json-encode-string to use the new implementation, which you'd need to copy.