abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.27k stars 337 forks source link

Startup speed #3019

Open yanchith opened 1 year ago

yanchith commented 1 year ago

Hi! Before I get to the issue at hand, I really want to thank everyone working on ivy for their work. swiper and counsel-rg were two of the three "killer apps" that made me switch from VS Code to Emacs in 2018 ❤️ The third one is magit.

Sorry, if this has been reported before, I didn't find any issue describing this.

I recently tried the vertico ecosystem, and while I almost immediately switched back to ivy for usability reasons, I did find its startup speed much better.

Including ivy in my config slows the emacs-init-time by about 40-50ms, depending on the computer.

This is the tabulated and tree output of benchmark-init:

  default                                                           load         14      14
  ivy                                                               require      14      43
  ivy-faces                                                         require      12      12
  whitespace                                                        require      10      10
  ring                                                              require       9       9
  abu-theme                                                         require       6       6
  color                                                             require       5       5
  finder-inf                                                        require       4       4
  ivy-overlay                                                       require       2       2
  ~/.emacs.d/lisp/abu-theme                                         load          1       1
  colir                                                             require       1       6
╼►[benchmark-init/root nil 78ms]
  ├─[default load 14ms]
  ├─[~/.emacs.d/lisp/abu-theme load 1ms]
  ├─[abu-theme require 6ms]
  ├─[ivy require 14ms]
  │ ├─[ring require 9ms]
  │ ├─[ivy-faces require 12ms]
  │ ├─[ivy-overlay require 2ms]
  │ ╰─[colir require 1ms]
  │   ╰─[color require 5ms]
  ├─[finder-inf require 4ms]
  ╰─[whitespace require 10ms]

I could try to load ivy lazily, but that would just transfer the wait to the time I use it for the first time, which is usually right after I open Emacs. Also, I've had troubles with lazy-loading ivy before.

Is this something that can be worked on or improved?


Not sure I do anything too exotic, but here's the config:

(use-package ivy
  :straight t
  ;; TODO(yan): @Perf This costs about 40ms of startup.
  :demand t                                            ;; We pretty much need ivy the moment we start
  :bind (("C-x b"   . ivy-switch-buffer)
         ("C-x 4 b" . ivy-switch-buffer-other-window))
  :config
  (setq ivy-use-selectable-prompt t)
  (ivy-mode 1))

(use-package swiper
  :straight t
  :bind ("C-s" . swiper))

(use-package counsel
  :straight t
  :bind (("M-x"     . counsel-M-x)
         ("C-x C-f" . counsel-find-file)
         ("C-c s g" . counsel-git-grep)
         ("C-c s r" . counsel-rg)))