minad / corfu

:desert_island: corfu.el - COmpletion in Region FUnction
GNU General Public License v3.0
1.14k stars 43 forks source link

corfu-auto takes too long to appear in some contexts #163

Closed tgolsson closed 2 years ago

tgolsson commented 2 years ago

Hello!

Recently I noticed that corfu sometimes takes significant amount of time to appear - over a second. Explicitly summoning corfu with tab is close to instant. It seems to be dependent on what I write.

If I'm in my init.el, for example right before the first line of my config below; and write *, it'll suggest :bind*, :bind-keymap* and :EXPORT_HUGO_SECTION* instantly. This seems like dabbrev suggestions. If I write (corf) it'll suggest a bunch of corfu functions after a couple of seconds.

Unfortunately I cannot tell when exactly this issue started occuring, as I still use company-mode for my daily driver modes due to familiarity.

I'm using the following configuration:

(use-package corfu
  :custom
  (corfu-cycle t)
  (corfu-auto t)
  (corfu-auto-delay 0.0)
  (corfu-auto-prefix 1)
  (corfu-commit-predicate nil)
  (corfu-quit-at-boundary t)
  (corfu-quit-no-match t)
  (corfu-echo-documentation t)

  :hook ((emacs-lisp-mode . corfu-mode)
         (shell-mode . corfu-mode)
         (eshell-mode . corfu-mode)))
minad commented 2 years ago

Can you provide a minimal recipe which I can try to reproduce with emacs -Q? Can you try to reduce the amount of adjustments to Corfu customization variables to narrow down the issue? Do it step by step. Note that the corfu-auto-delay=0 setting puts high load on the completion backend and the garbage collector. Furthermore the combination with a minimal prefix length of 1 generates many candidates. Therefore you probably observe garbage collector pauses or it takes a long time to generate the candidates. The behavior you observe is likely not a bug but a consequence of these inefficient configuration settings.

tgolsson commented 2 years ago

After a lot of bisecting my config for a -Q test, this is simply the same as #55 - I'm using flyspell-prog-mode.

minad commented 2 years ago

Okay, then I guess we solved the issue. I recommend to not use flyspell-prog-mode and flyspell in general since it seems to be very inefficient. The time taken by flyspell is unfortunately not available for other features like Corfu.

tgolsson commented 2 years ago

Yeah; it's a shame but I guess I have to sacrifice it. I'm curious whether it'd be possible to implement something like Auto-Complete has to advice the flyspell post-command hook: ac-flyspell-workaround.

minad commented 2 years ago

I won't implement workarounds in Corfu but you can put something in your config. If you look at auto-complete.el the workaround has been added there 12 years ago.

https://github.com/auto-complete/auto-complete/blame/57cb8f2ee32dff17ea1b4431fe5920272aa38d72/auto-complete.el#L1928

Nothing good comes from adding workarounds. It is better to fix the actual cause to the bug at some point. It could have happened ten years ago...