Simplify and decouple init files
The two doom-gc-* variables in init.el couples the rest of the config to these two files. The bulk of GC/file-handler optimization was moved into core.el and simplified (all that idle-timer voodoo was overkill). Also adds (setq frame-inhibit-implied-reize t) to early-init, which speeds up startup a fair bit in some edge cases with larger fonts. squash! Simplify and decouple init files
This commit is contained in:
parent
8147bc1aee
commit
81ab3dbc5d
4 changed files with 118 additions and 136 deletions
64
init.el
64
init.el
|
@ -27,61 +27,23 @@
|
|||
;;
|
||||
;;; License: MIT
|
||||
|
||||
(defvar doom-gc-cons-threshold 16777216 ; 16mb
|
||||
"The default value to use for `gc-cons-threshold'. If you experience freezing,
|
||||
decrease this. If you experience stuttering, increase this.")
|
||||
|
||||
(defvar doom-gc-cons-upper-limit 536870912 ; 512mb
|
||||
"The temporary value for `gc-cons-threshold' to defer it.")
|
||||
|
||||
|
||||
(defvar doom--file-name-handler-alist file-name-handler-alist)
|
||||
|
||||
(defun doom-restore-startup-optimizations-h ()
|
||||
"Resets garbage collection settings to reasonable defaults (a large
|
||||
`gc-cons-threshold' can cause random freezes otherwise) and resets
|
||||
`file-name-handler-alist'."
|
||||
(setq file-name-handler-alist doom--file-name-handler-alist)
|
||||
;; Do this on idle timer to defer a possible GC pause that could result; also
|
||||
;; allows deferred packages to take advantage of these optimizations.
|
||||
(run-with-idle-timer
|
||||
3 nil
|
||||
(lambda ()
|
||||
(setq-default gc-cons-threshold doom-gc-cons-threshold)
|
||||
;; To speed up minibuffer commands (like helm and ivy), we defer garbage
|
||||
;; collection while the minibuffer is active.
|
||||
(defun doom-defer-garbage-collection-h ()
|
||||
(setq gc-cons-threshold doom-gc-cons-upper-limit))
|
||||
(defun doom-restore-garbage-collection-h ()
|
||||
;; Defer it so that commands launched from the minibuffer can enjoy the
|
||||
;; benefits.
|
||||
(run-at-time 1 nil (lambda () (setq gc-cons-threshold doom-gc-cons-threshold))))
|
||||
(add-hook 'minibuffer-setup-hook #'doom-defer-garbage-collection-h)
|
||||
(add-hook 'minibuffer-exit-hook #'doom-restore-garbage-collection-h)
|
||||
;; GC all sneaky breeky like
|
||||
(add-hook 'focus-out-hook #'garbage-collect))))
|
||||
|
||||
|
||||
(if (ignore-errors (or after-init-time noninteractive))
|
||||
(setq gc-cons-threshold doom-gc-cons-threshold)
|
||||
;; A big contributor to startup times is garbage collection. We up the gc
|
||||
;; threshold to temporarily prevent it from running, then reset it later in
|
||||
;; `doom-restore-startup-optimizations-h'.
|
||||
(setq gc-cons-threshold doom-gc-cons-upper-limit)
|
||||
;; This is consulted on every `require', `load' and various path/io functions.
|
||||
;; You get a minor speed up by nooping this.
|
||||
(setq file-name-handler-alist nil)
|
||||
;; Not restoring these to their defaults will cause stuttering/freezes.
|
||||
(add-hook 'after-init-hook #'doom-restore-startup-optimizations-h))
|
||||
|
||||
(when (version< emacs-version "25.3")
|
||||
(error "Detected Emacs %s. Doom only supports Emacs 25.3 and higher"
|
||||
emacs-version))
|
||||
|
||||
;; Ensure Doom is running out of this file's directory
|
||||
(setq user-emacs-directory (file-name-directory load-file-name))
|
||||
;; In noninteractive sessions, prioritize non-byte-compiled source files to
|
||||
;; prevent stale, byte-compiled code from running. However, if you're getting
|
||||
;; recursive load errors, it may help to set this to nil.
|
||||
(setq load-prefer-newer noninteractive)
|
||||
|
||||
;; A big contributor to startup times is garbage collection. We up the gc
|
||||
;; threshold to temporarily prevent it from running, then reset it later with
|
||||
;; `doom-restore-garbage-collection-h'. Not resetting it will cause
|
||||
;; stuttering/freezes.
|
||||
(setq gc-cons-threshold most-positive-fixnum)
|
||||
|
||||
;; In noninteractive sessions, prioritize non-byte-compiled source files to
|
||||
;; prevent the use of stale byte-code. Otherwise, it saves us a little IO time
|
||||
;; to skip the mtime checks on every *.elc file we load.
|
||||
(setq load-prefer-newer noninteractive)
|
||||
|
||||
;; Let 'er rip!
|
||||
(require 'core (concat user-emacs-directory "core/core"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue