💾 Archived View for gemlog.blue › users › kristof › 1612884617.gmi captured on 2023-07-22 at 18:22:44. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-12-04)
-=-=-=-=-=-=-
From time to time it is appropriate to revise even a working configuration. Of course, this is even more true for an environment as omnipotent as emacs.
My latest changes were mostly about speeding up the startup of emacs. To be able to assess the changes in terms of their impact on startup speed, I resorted to the built-in emacs function emacs-init-time. My goal was a time in the range of one second (± 0.5 seconds).
The most trusty companion to reduce emacs’ startup time is certainly use-package. While require simply loads an (installed) package at startup, use-package lets you specify some subtleties. For example, :ensure t can be used to ensure that a package is also installed before it is used. To improve the start time, however, :hook, :after or :commands, for example, play a more important part.
With :hook the loading of the package can be deferred until the execution of a specific hook of another package.
So, instead of loading org right away by using
(require 'org)
with use-package the loading of org can be deferred until the package is needed, e.g., when org-mode is invoked:
(use-package org :hook org-mode)
With :after we can ensure that, e.g., package y is not loaded until package x has already been loaded. Either, because package y cannot fulfill its function without package z or its functionality is otherwise not needed at all.
For example, the package org-bullets is pretty useless without org itself. So instead of loading org-package right away, with use-package we can ensure org-bullets is only loaded when org is already available:
(use-package org-bullets :after org)
:commands, similar to :hook, defers the loading of a package. However, the deferral here is not tied to a hook, but to an actual command.
For example, we only need to load the package elpher, a Gopher and Gemini client, when we want to use elpher, i.e. explicitly open it with M-x elpher. With use-package we can configure this accordingly:
(use-package elpher :commands elpher)
By replacing require with use-package and some sensible deferral measures, I was able to reduce the startup time of emacs to about one second. Mission accomplished!
If of any interest, my emacs configuration is available at GitHub: