Refactor startup optimizations
+ Add doom-gc-cons-upper-limit variable + Don't use most-positive-fixnum, in case Emacs somehow wants to allocate that much! + Don't use startup optimizations in noninteractive sessions + Restore gc-cons-threshold on idle timer, instead of hook (to defer the possible GC pause and so deferred packages can take advantage of these optimizations).
This commit is contained in:
parent
81ee563c4c
commit
eaa10946f1
2 changed files with 33 additions and 23 deletions
15
core/core.el
15
core/core.el
|
@ -300,7 +300,7 @@ original value of `symbol-file'."
|
||||||
|
|
||||||
;; Don't garbage collect to speed up minibuffer commands
|
;; Don't garbage collect to speed up minibuffer commands
|
||||||
(defun doom|defer-garbage-collection ()
|
(defun doom|defer-garbage-collection ()
|
||||||
(setq gc-cons-threshold most-positive-fixnum))
|
(setq gc-cons-threshold doom-gc-cons-upper-limit))
|
||||||
(defun doom|restore-garbage-collection ()
|
(defun doom|restore-garbage-collection ()
|
||||||
(setq gc-cons-threshold doom-gc-cons-threshold))
|
(setq gc-cons-threshold doom-gc-cons-threshold))
|
||||||
(add-hook 'minibuffer-setup-hook #'doom|defer-garbage-collection)
|
(add-hook 'minibuffer-setup-hook #'doom|defer-garbage-collection)
|
||||||
|
@ -318,12 +318,13 @@ easier to tell where the came from.
|
||||||
Meant to be used with `run-hook-wrapped'."
|
Meant to be used with `run-hook-wrapped'."
|
||||||
(when doom-debug-mode
|
(when doom-debug-mode
|
||||||
(message "Running doom hook: %s" hook))
|
(message "Running doom hook: %s" hook))
|
||||||
(condition-case e
|
(let ((gc-cons-threshold doom-gc-cons-upper-limit))
|
||||||
(funcall hook)
|
(condition-case e
|
||||||
((debug error)
|
(funcall hook)
|
||||||
(signal 'doom-hook-error (list hook e))))
|
((debug error)
|
||||||
;; return nil so `run-hook-wrapped' won't short circuit
|
(signal 'doom-hook-error (list hook e))))
|
||||||
nil)
|
;; return nil so `run-hook-wrapped' won't short circuit
|
||||||
|
nil))
|
||||||
|
|
||||||
(defun doom-ensure-same-emacs-version-p ()
|
(defun doom-ensure-same-emacs-version-p ()
|
||||||
"Check if the running version of Emacs has changed and set
|
"Check if the running version of Emacs has changed and set
|
||||||
|
|
41
init.el
41
init.el
|
@ -27,30 +27,38 @@
|
||||||
;;
|
;;
|
||||||
;;; License: MIT
|
;;; License: MIT
|
||||||
|
|
||||||
(defvar doom-gc-cons-threshold (* 8 1024 1024)
|
(defvar doom-gc-cons-threshold 16777216 ; 16mb
|
||||||
"The default value to use for `gc-cons-threshold'.")
|
"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 268435456 ; 256mb
|
||||||
|
"The temporary value for `gc-cons-threshold' to defer it.")
|
||||||
|
|
||||||
|
|
||||||
(defvar doom--file-name-handler-alist file-name-handler-alist)
|
(defvar doom--file-name-handler-alist file-name-handler-alist)
|
||||||
(unless after-init-time
|
|
||||||
|
(defun doom|restore-startup-optimizations ()
|
||||||
|
"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
|
||||||
|
gc-cons-threshold doom-gc-cons-threshold))
|
||||||
|
|
||||||
|
|
||||||
|
(if (or after-init-time noninteractive)
|
||||||
|
(setq gc-cons-threshold doom-gc-cons-threshold)
|
||||||
;; A big contributor to long startup times is the garbage collector, so we up
|
;; A big contributor to long startup times is the garbage collector, so we up
|
||||||
;; its memory threshold, temporarily and reset it later in
|
;; its memory threshold, temporarily and reset it later in
|
||||||
;; `doom|disable-startup-optimizations'.
|
;; `doom|disable-startup-optimizations'.
|
||||||
(setq gc-cons-threshold most-positive-fixnum)
|
(setq gc-cons-threshold doom-gc-cons-upper-limit) ; 256mb
|
||||||
;; This is consulted on every `require', `load' and various file reading
|
;; This is consulted on every `require', `load' and various file reading
|
||||||
;; functions. You get a minor speed up by nooping this.
|
;; functions. You get a minor speed up by nooping this.
|
||||||
(setq file-name-handler-alist nil))
|
(setq file-name-handler-alist nil)
|
||||||
|
;; Restore these to their defaults later. Do it on an idle timer to defer the
|
||||||
(defun doom|disable-startup-optimizations ()
|
;; possible GC pause, and to give deferred packages the ability to take
|
||||||
"Resets garbage collection settings to reasonable defaults (if you don't do
|
;; advantage of these optimizations.
|
||||||
this, you'll get stuttering and random freezes) and resets
|
(run-with-idle-timer 5 nil #'doom|restore-startup-optimizations)
|
||||||
`file-name-handler-alist'."
|
(add-hook 'doom-reload-hook #'doom|restore-startup-optimizations))
|
||||||
(setq file-name-handler-alist doom--file-name-handler-alist
|
|
||||||
gc-cons-threshold doom-gc-cons-threshold)
|
|
||||||
(makunbound 'doom--file-name-handler-alist))
|
|
||||||
|
|
||||||
(add-hook 'emacs-startup-hook #'doom|disable-startup-optimizations)
|
|
||||||
(add-hook 'doom-reload-hook #'doom|disable-startup-optimizations)
|
|
||||||
|
|
||||||
|
|
||||||
;; Ensure Doom is always running out of this file's directory
|
;; Ensure Doom is always running out of this file's directory
|
||||||
|
@ -60,5 +68,6 @@ this, you'll get stuttering and random freezes) and resets
|
||||||
;; load errors, it may help to set this to nil.
|
;; load errors, it may help to set this to nil.
|
||||||
(setq load-prefer-newer noninteractive)
|
(setq load-prefer-newer noninteractive)
|
||||||
|
|
||||||
|
|
||||||
;; Let 'er rip!
|
;; Let 'er rip!
|
||||||
(require 'core (concat user-emacs-directory "core/core"))
|
(require 'core (concat user-emacs-directory "core/core"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue