reddit / emacs

My init.el takes 4 secs but has no obvious bottleneck?

luiggi_oasis · 2022-12-18 18:42
So I'm profiling my init.el with ESUP and unfortunately I can't find a bottleneck. It's just a sum of small pieces that makes it overall \~3.2 seconds. Note that I'm using use-package with ensure t to enforce lazy loading globally with \`(require 'use-package-ensure)\` and \`(setq use-package-always-ensure t)\`. **UPDATE** It turns out I had ensure, but not defer, set globally. So lazy loading was actually off! Thank you to those who pointed that out. Here's the NEW ESUP output, which still **takes 2.29 secs**. Total User Startup Time: 2.290sec Total Number of GC Pauses: 18 Total GC Time: 0.324sec init.el:784 0.646sec 28% (eval-when-compile (require 'easy-mmode) (require 'ox)) init.el:6 0.545sec 23% (package-initialize) init.el:758 0.252sec 11% (set-face-attribute 'default nil :family "Roboto Mono" :weight 'light :height 120) init.el:659 0.144sec 6% (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(TeX-engine 'luatex) '(TeX-view-program-list '(("Zathura" ("zathura %o") ""))) '(TeX-view-program-selection '(((output-dvi has-no-display-manager) "dvi2tty") ((output-dvi style-pstricks) "dvips and gv") (output-dvi "xdvi") (output-pdf "Zathura") (output-html "xdg-open"))) '(desktop-load-locked-desktop t) '(desktop-restore-forces-onscreen nil t) '(desktop-restore-frames t) '(esup-depth 0) '(inhibit-startup-screen t) '(package-selected-packages '(wrap-region org-superstar imenu-list poly-R ox-tiddly dap-mode lsp-treemacs lsp-ivy helm-lsp lsp-ui lsp-mode comment-dwim-2 ix\.el ix parsebib helm-bibtex ebib biblio org-cliplink wc-mode helpful latex-preview-pane wgrep pdf-tools sr-speedbar key-chord ox-twbs ox htmlize markdown-preview-mode ess xclip workgroups2 which-key use-package treemacs smartparens rainbow-mode poly-markdown magit iedit hl-todo helm gitignore-mode flycheck expand-region csv-mode company backup-each-save auctex anzu)) '(safe-local-variable-values '((sr-speedbar-right-side) (sr-speedbar-toggle . t) (flycheck-mode) (eval TeX-run-style-hooks "beamer"))) '(save-place-mode t) '(scroll-bar-mode nil) '(show-paren-mode t) '(tool-bar-mode nil)) init.el:277 0.105sec 4% (use-package company :init (global-company-mode) ) init.el:317 0.100sec 4% (use-package flycheck :init (global-flycheck-mode) :config (setq flycheck-global-modes '(not ess-r-mode)) ) init.el:311 0.079sec 3% (use-package rainbow-mode :init (rainbow-mode) ) init.el:780 0.075sec 3% (load-theme 'dracula t) init.el:12 0.050sec 2% (eval-when-compile ;; Following line is not needed if use-package.el is in ~/.emacs.d (add-to-list 'load-path "<path where use-package is installed>") (require 'use-package)) init.el:199 0.046sec 2% (require 'ibuf-ext) init.el:4 0.040sec 1% (require 'package) init.el:162 0.038sec 1% (ffap-bindings) init.el:256 0.036sec 1% (use-package whitespace-cleanup-mode :init (whitespace-cleanup-mode t)) init.el:65 0.036sec 1% (use-package backup-each-save :hook (after-save . backup-each-save)) init.el:299 0.028sec 1% (use-package xclip :init (xclip-mode) ) init.el:307 0.026sec 1% (use-package smartparens :init (smartparens-mode) ) init.el:69 0.015sec 0% (global-auto-revert-mode 1) init.el:107 0.015sec 0% (use-package imenu-list :config (setq imenu-list-position 'left imenu-list-size 28 imenu-list-focus-after-activation t) :bind ("<f7>" . imenu-list-smart-toggle)) init.el:371 0.011sec 0% (use-package which-key :init (which-key-mode))
nv-elisp · 2022-12-18 18:55
> Note that I'm using use-package with ensure t to enforce lazy loading globally with `(require 'use-package-ensure)` and `(setq use-package-always-ensure t)`. `:ensure` makes sure the package is installed before it is required. It does not defer the loading of a package on its own. Maybe you're thinking of `use-package-always-defer`?
thetemp_ · 2022-12-18 18:56
> Note that I'm using use-package with ensure t to enforce lazy loading globally with `(require 'use-package-ensure)` and `(setq use-package-always-ensure t)`. `ensure` doesn't enforce lazy-loading. It just "ensures" that a package is installed. You want either `:defer t` or the global setting, `(setq use-package-always-defer t)`, which you can override with `:demand t` to explicitly load a package on startup. If you use either `:defer` or the global setting, just make sure you have some way of loading the package when you need it, such as a keybinding that will autoload it.
[deleted] · 2022-12-18 20:11
[deleted]
luiggi_oasis · 2022-12-18 20:11
Thank you pointing this out. I definitely was thinking of always-deferinstead of always-ensure. It turns out that defer was not setglobally, I just set defer globally true via use-package-always-deferand updated the OP. The initialization time reduced from 3.2 to 2.2seconds with the first 2-4 items (easy-mmode, ox, package initialize)being the bottenecks. There's also set-face-attribute andcustom-set-variables but that's fine I guess.
luiggi_oasis · 2022-12-18 20:11
Thank you pointing this out. I definitely was thinking of always-deferinstead of always-ensure. It turns out that defer was not setglobally, I just set defer globally true via use-package-always-deferand updated the OP. The initialization time reduced from 3.2 to 2.2seconds with the first 2-4 items (easy-mmode, ox, package initialize)being the bottenecks. There's also set-face-attribute andcustom-set-variables but that's fine I guess.
0lMon · 2022-12-18 20:29
Hej Hej, If I am not mistaken initializing packages is not needed any more. Check out the `package-enable-at-startup` variable. If you do not change the value of this variable to `nil` in your early-init file, you do not have to call `(package-initialize)` Cheers!
cradlemann · 2022-12-18 21:00
You can check my [config](https://github.com/Crandel/home/tree/master/.config/emacs). For me Emacs starts less than second
MitchellMarquez42 · 2022-12-18 21:02
That first `eval-when-compile` is probably unnecessary. You can replace the ox line with (use-package ox :after org) Not sure about the other one but probably similar idea.
PhantomSeahorse · 2022-12-18 21:07
Look into emacs server - client
luiggi_oasis · 2022-12-18 21:12
Thanks, I'll try removing that line for a couple days and see if it introduces any issues. I wasn't sure why I had that line but I tracked it down to the suggested way to load the MELPA repository: https://melpa.org/#/getting-started
[deleted] · 2022-12-18 21:19
[deleted]
luiggi_oasis · 2022-12-18 21:19
Oh, I took that line verbatim from alphapapa, I'll try tinkering around with it and see if it helps [https://github.com/alphapapa/unpackaged.el/blob/007d465798f379e69d76d61628f3a400f7297dea/README.org#export-to-html-with-useful-anchors](https://github.com/alphapapa/unpackaged.el/blob/007d465798f379e69d76d61628f3a400f7297dea/README.org#export-to-html-with-useful-anchors) Thanks!
luiggi_oasis · 2022-12-18 21:26
But how do you do that?! I have the following in my init, which you also have (https://github.com/Crandel/home/blob/master/.config/emacs/init.el#L21), and it takes .60 seconds! eval-when-compile (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (package-initialize))
cradlemann · 2022-12-18 22:33
This is an output of esup command for my setup Total User Startup Time: 0.004sec Total Number of GC Pauses: 0 Total GC Time: 0.000sec init.el:3 0.004sec 99% (eval-after-load 'gnutls '(add-to-list 'gnutls-trustfiles "/etc/ssl/cert.pem")) package.elc:12 0.000sec 0% (defalias 'package-check-signature #[0 \301=\203\302\303!\210\304\305!\205\301\20\207" [package-check-signature allow-unsigned require epg-config epg-find-configuration OpenPGP] 2 (#$ . 8443)])
theunixman · 2022-12-18 22:41
Man 4 seconds is a pipe dream haha!
luiggi_oasis · 2022-12-19 12:56
.004 secs is mighty impressive, do you use the emacs daemon along with emacsclient? or is it a init from scratch?
cradlemann · 2022-12-19 13:21
I have no need for daemon-mode