perf: add additional startup optimizations
Also switches `expand-file-name` calls with the much faster `file-name-concat` where possible.
This commit is contained in:
parent
42d88421ba
commit
57a91235bd
2 changed files with 53 additions and 19 deletions
|
@ -2,8 +2,6 @@
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(require 'doom-modules)
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;;; Custom hooks
|
;;; Custom hooks
|
||||||
|
@ -310,8 +308,15 @@ If RETURN-P, return the message as a string instead of displaying it."
|
||||||
(autoload 'doom-initialize-packages "doom-packages")
|
(autoload 'doom-initialize-packages "doom-packages")
|
||||||
(eval-after-load 'package '(require 'doom-packages))
|
(eval-after-load 'package '(require 'doom-packages))
|
||||||
(eval-after-load 'straight '(doom-initialize-packages))
|
(eval-after-load 'straight '(doom-initialize-packages))
|
||||||
|
(require 'doom-modules)
|
||||||
|
|
||||||
;; Load all things.
|
;; Undo any problematic startup optimizations; from this point, I make no
|
||||||
|
;; assumptions about what might be loaded in userland.
|
||||||
|
(when (get 'load-suffixes 'initial-value)
|
||||||
|
(setq load-suffixes (get 'load-suffixes 'initial-value)
|
||||||
|
load-file-rep-suffixes (get 'load-file-rep-suffixes 'initial-value)))
|
||||||
|
|
||||||
|
;; Load user config + modules
|
||||||
(doom-initialize-modules)
|
(doom-initialize-modules)
|
||||||
|
|
||||||
(provide 'doom-start)
|
(provide 'doom-start)
|
||||||
|
|
61
lisp/doom.el
61
lisp/doom.el
|
@ -89,6 +89,7 @@
|
||||||
;; Remember these variables' initial values, so we can safely reset them at a
|
;; Remember these variables' initial values, so we can safely reset them at a
|
||||||
;; later time, or consult them without fear of contamination.
|
;; later time, or consult them without fear of contamination.
|
||||||
(dolist (var '(exec-path load-path process-environment
|
(dolist (var '(exec-path load-path process-environment
|
||||||
|
load-suffixes load-file-rep-suffixes
|
||||||
file-name-handler-alist))
|
file-name-handler-alist))
|
||||||
(unless (get var 'initial-value)
|
(unless (get var 'initial-value)
|
||||||
(put var 'initial-value (default-toplevel-value var))))
|
(put var 'initial-value (default-toplevel-value var))))
|
||||||
|
@ -191,6 +192,31 @@
|
||||||
(define-advice startup--load-user-init-file (:before (&rest _) undo-silence)
|
(define-advice startup--load-user-init-file (:before (&rest _) undo-silence)
|
||||||
(advice-remove #'load-file #'load-file@silence))
|
(advice-remove #'load-file #'load-file@silence))
|
||||||
|
|
||||||
|
;; PERF: `load-suffixes' and `load-file-rep-suffixes' are consulted on each
|
||||||
|
;; `require' and `load'. Doom won't load any dmodules this early, so omit
|
||||||
|
;; .so for a small startup boost. This is later restored in doom-start.
|
||||||
|
(set-default-toplevel-value 'load-suffixes '(".elc" ".el"))
|
||||||
|
(set-default-toplevel-value 'load-file-rep-suffixes '(""))
|
||||||
|
|
||||||
|
;; PERF: The mode-line procs a couple dozen times during startup. This is
|
||||||
|
;; normally quite fast, but disabling the default mode-line and reducing the
|
||||||
|
;; update delay timer seems to stave off ~30-50ms.
|
||||||
|
(setq-default mode-line-format nil)
|
||||||
|
(dolist (buf (buffer-list))
|
||||||
|
(with-current-buffer buf (setq mode-line-format nil)))
|
||||||
|
;; PERF,UX: Premature redisplays can substantially affect startup times and
|
||||||
|
;; produce ugly flashes of unstyled Emacs.
|
||||||
|
(setq-default inhibit-redisplay t
|
||||||
|
inhibit-message t)
|
||||||
|
;; COMPAT: Then reset it with advice, because `startup--load-user-init-file'
|
||||||
|
;; will never be interrupted by errors. And if these settings are left
|
||||||
|
;; set, Emacs could appear frozen or garbled.
|
||||||
|
(define-advice startup--load-user-init-file (:after (&rest _) undo-inhibit-vars)
|
||||||
|
(setq-default inhibit-redisplay nil
|
||||||
|
inhibit-message nil)
|
||||||
|
(unless (default-toplevel-value 'mode-line-format)
|
||||||
|
(setq-default mode-line-format (get 'mode-line-format 'initial-value))))
|
||||||
|
|
||||||
;; PERF: Unset a non-trivial list of command line options that aren't
|
;; PERF: Unset a non-trivial list of command line options that aren't
|
||||||
;; relevant to our current OS, but `command-line-1' still processes.
|
;; relevant to our current OS, but `command-line-1' still processes.
|
||||||
(unless IS-MAC
|
(unless IS-MAC
|
||||||
|
@ -291,14 +317,16 @@
|
||||||
"The root directory for Doom's modules. Must end with a slash.")
|
"The root directory for Doom's modules. Must end with a slash.")
|
||||||
|
|
||||||
(defconst doom-user-dir
|
(defconst doom-user-dir
|
||||||
(if-let (doomdir (getenv-internal "DOOMDIR"))
|
(expand-file-name
|
||||||
(expand-file-name (file-name-as-directory doomdir))
|
(if-let (doomdir (getenv-internal "DOOMDIR"))
|
||||||
(or (let ((xdgdir
|
(file-name-as-directory doomdir)
|
||||||
(expand-file-name "doom/"
|
(or (let ((xdgdir
|
||||||
(or (getenv-internal "XDG_CONFIG_HOME")
|
(file-name-concat
|
||||||
"~/.config"))))
|
(or (getenv-internal "XDG_CONFIG_HOME")
|
||||||
(if (file-directory-p xdgdir) xdgdir))
|
"~/.config")
|
||||||
"~/.doom.d/"))
|
"doom/")))
|
||||||
|
(if (file-directory-p xdgdir) xdgdir))
|
||||||
|
"~/.doom.d/")))
|
||||||
"Where your private configuration is placed.
|
"Where your private configuration is placed.
|
||||||
|
|
||||||
Defaults to ~/.config/doom, ~/.doom.d or the value of the DOOMDIR envvar;
|
Defaults to ~/.config/doom, ~/.doom.d or the value of the DOOMDIR envvar;
|
||||||
|
@ -391,9 +419,10 @@ This file is responsible for informing Emacs where to find all of Doom's
|
||||||
autoloaded core functions (in lisp/lib/*.el).")
|
autoloaded core functions (in lisp/lib/*.el).")
|
||||||
|
|
||||||
(defconst doom-env-file
|
(defconst doom-env-file
|
||||||
(if doom-profile
|
(file-name-concat (if doom-profile
|
||||||
(expand-file-name "env" doom-profile-dir)
|
doom-profile-dir
|
||||||
(concat doom-local-dir "env"))
|
doom-local-dir)
|
||||||
|
"env")
|
||||||
"The location of your envvar file, generated by `doom env`.
|
"The location of your envvar file, generated by `doom env`.
|
||||||
|
|
||||||
This file contains environment variables scraped from your shell environment,
|
This file contains environment variables scraped from your shell environment,
|
||||||
|
@ -443,22 +472,22 @@ users).")
|
||||||
;; ...However, this may surprise packages (and users) that read
|
;; ...However, this may surprise packages (and users) that read
|
||||||
;; `user-emacs-directory' expecting to find the location of your Emacs config,
|
;; `user-emacs-directory' expecting to find the location of your Emacs config,
|
||||||
;; such as server.el!
|
;; such as server.el!
|
||||||
(setq server-auth-dir (expand-file-name "server/" doom-emacs-dir))
|
(setq server-auth-dir (file-name-concat doom-emacs-dir "server/"))
|
||||||
|
|
||||||
;; Packages with file/dir settings that don't use `user-emacs-directory' or
|
;; Packages with file/dir settings that don't use `user-emacs-directory' or
|
||||||
;; `locate-user-emacs-file' to initialize will need to set explicitly, to stop
|
;; `locate-user-emacs-file' to initialize will need to set explicitly, to stop
|
||||||
;; them from littering in ~/.emacs.d/.
|
;; them from littering in ~/.emacs.d/.
|
||||||
(setq desktop-dirname (expand-file-name "desktop" doom-cache-dir)
|
(setq desktop-dirname (file-name-concat doom-cache-dir "desktop")
|
||||||
pcache-directory (expand-file-name "pcache/" doom-cache-dir))
|
pcache-directory (file-name-concat doom-cache-dir "pcache/"))
|
||||||
|
|
||||||
;; Allow the user to store custom.el-saved settings and themes in their Doom
|
;; Allow the user to store custom.el-saved settings and themes in their Doom
|
||||||
;; config (e.g. ~/.doom.d/).
|
;; config (e.g. ~/.doom.d/).
|
||||||
(setq custom-file (expand-file-name "custom.el" doom-user-dir))
|
(setq custom-file (file-name-concat doom-user-dir "custom.el"))
|
||||||
|
|
||||||
;; By default, Emacs stores `authinfo' in $HOME and in plain-text. Let's not do
|
;; By default, Emacs stores `authinfo' in $HOME and in plain-text. Let's not do
|
||||||
;; that, mkay? This file stores usernames, passwords, and other treasures for
|
;; that, mkay? This file stores usernames, passwords, and other treasures for
|
||||||
;; the aspiring malicious third party. You'll need a GPG setup though.
|
;; the aspiring malicious third party. You'll need a GPG setup though.
|
||||||
(setq auth-sources (list (concat doom-data-dir "authinfo.gpg")
|
(setq auth-sources (list (file-name-concat doom-data-dir "authinfo.gpg")
|
||||||
"~/.authinfo.gpg"))
|
"~/.authinfo.gpg"))
|
||||||
|
|
||||||
(define-advice en/disable-command (:around (fn &rest args) write-to-data-dir)
|
(define-advice en/disable-command (:around (fn &rest args) write-to-data-dir)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue