minad / corfu

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

The speed of triggering the candidate list for the first time is very slow. #325

Closed hongyi-zhao closed 1 year ago

hongyi-zhao commented 1 year ago

I'm using corfu via use-package as follows:

(use-package corfu
  :demand t
  ;; Optional customizations
  :custom
  ;; (corfu-cycle t)                ;; Enable cycling for `corfu-next/previous'
  (corfu-auto t)                 ;; Enable auto completion
  (corfu-auto-prefix 2)
  ;; (corfu-separator ?\s)          ;; Orderless field separator
  ;; (corfu-quit-at-boundary nil)   ;; Never quit at completion boundary
  ;; (corfu-quit-no-match nil)      ;; Never quit, even if there is no match
  ;; (corfu-preview-current nil)    ;; Disable current candidate preview
  ;; (corfu-preselect 'prompt)      ;; Preselect the prompt
  ;; (corfu-on-exact-match nil)     ;; Configure handling of exact matches
  ;; (corfu-scroll-margin 5)        ;; Use scroll margin

  ;; Enable Corfu only for certain modes.
  ;; :hook ((prog-mode . corfu-mode)
  ;;        (shell-mode . corfu-mode)
  ;;        (eshell-mode . corfu-mode))

  ;; Recommended: Enable Corfu globally.
  ;; This is recommended since Dabbrev can be used globally (M-/).
  ;; See also `corfu-exclude-modes'.
  :init
  (global-corfu-mode))

;; A few more useful configurations...
(use-package emacs
  :init
  ;; TAB cycle if there are only few candidates
  ;; (setq completion-cycle-threshold 3)

  ;; Emacs 28: Hide commands in M-x which do not apply to the current mode.
  ;; Corfu commands are hidden, since they are not supposed to be used via M-x.
  ;; (setq read-extended-command-predicate
  ;;       #'command-completion-default-include-p)

  ;; Enable indentation+completion using the TAB key.
  ;; `completion-at-point' is often bound to M-TAB.
  (setq tab-always-indent 'complete))

Though I've set the :demand t in the corfu's use-package configuration, but the speed of triggering the candidate list for the first time is still very slow: it takes a second before it's ready to go.

Any tips for fixing this problem? See here for the related discussion.

Regards, Zhao

minad commented 1 year ago

I cannot tell what the exact problem is, but it is likely an issue of the backend, which is inefficient and slow to start. In the discussion, Arash noted that Company is equally slow to startup, see https://lists.gnu.org/archive/html/auctex/2023-05/msg00050.html. If I run Corfu in Elisp buffers for example it starts quickly. If Corfu would be slow with fast backends, then it could be a Corfu or child frame problem.

;; Test fast backend
(setq completion-at-point-functions '(elisp-completion-at-point))
      corfu-auto t
      corfu-auto-delay 0
      corfu-auto-prefix 1)
(corfu-mode 1)
minad commented 1 year ago

I have another possible explanation - at the first start Emacs may have to load additional fonts due to the TeX completion preview in the Corfu popup. I've seen a similar problem with cape-tex from my Cape package. We cannot do much about this startup overhead. At least it should be gone after first use.

hongyi-zhao commented 1 year ago

But till now, I still encounter the following problems:

  1. After I've enabled the following option, continuous pressing Tab key doesn't cycle through the candidates.

(setq completion-cycle-threshold 3)

  1. Package names still cannot be automatically completed, as shown in the attached screenshot:

image

minad commented 1 year ago

@hongyi-zhao

That's an unrelated problem, but again probably not due to Corfu. Cycling works well if you use compliant backends like the aforementioned elisp-completion-at-point. If package name completion does not work properly, that's again a problem of the backend.

I've noticed that you recently opened multiple bug reports for my Corfu and Vertico packages, which were actually support requests. Please note that I maintain many packages, which already require a lot of attention, such that I have to focus on actual bugs. Your reports lack details and were not directly caused by Corfu. For the future, before opening an issue, please make sure that you first check if the issue is actually an issue of Corfu by testing compliant backends and by testing a minimal recipe starting from emacs -Q. Thanks!