clojure-emacs/ac-nrepl

ac-nrepl perceptibly slow. Any way to speed up?

abo-abo opened this issue · 5 comments

With ac-nrepl on, I notice a delay in responsiveness as I type.
The reason, I think, could be that it tries to talk to nrepl as I type,
and nrepl doesn't respond fast enough.

I've got ac-delay on 0.1s, and it works great for e.g. ac-source-words-in-same-mode-buffers or elisp stuff.

Is it possible to have ac-delay on 0.1s for fast sources, and 0.5s for ac-nrepl sources?

Is it possible to choose to cache all completions and not to talk to nrepl at all?
Or, even better, start talking to nrepl only after a custom period of inactivity?

Hmm. The issue here is really that auto-complete works synchronously; I wouldn't advise using ac-nrepl or other non-trivial completion sources in conjunction with ac-auto-start. In other words, try setting that variable to nil, so that you need to explicitly trigger completion.

ac-delay controls how long auto-complete waits before checking all its configured sources, so there's no way to treat ac-nrepl differently here. Introducing caching is a slippery slope, particularly in such a dynamic language environment where definitions can change dramatically: we already cache java class names, but that's pretty much the limit of what can be done safely.

Thanks for the answer. I think I can get away with using this one:

(defun clojure-auto-complete ()
  (interactive)
  (let ((ac-sources
         `(ac-source-nrepl-ns
           ac-source-nrepl-vars
           ac-source-nrepl-ns-classes
           ac-source-nrepl-all-classes
           ac-source-nrepl-java-methods
           ac-source-nrepl-static-methods
           ,@ac-sources)))
  (auto-complete)))

ac-auto-start is just too good to give up.

I don't think that code does what you think: it temporarily binds ac-sources to a different value, and then discards the value, before just calling auto-complete. So that clojure-auto-complete function is equivalent to auto-complete.

And in any case, the value of ac-sources you're trying to construct should be the same as what results from calling ac-nrepl-setup, so the function wouldn't change any behaviour.

Nope. (auto-complete) is called with let binding still active.
I turned off ac-nrepl-setup, so ac-nrepl sources are in ac-sources only in this one
place, where I call it with a shortcut. In other cases, I'm getting auto completion from
fast sources.

Ah, sorry, I mis-counted the parens and was thrown off by the indentation. Now I understand your intent. :-)