diff --git a/core/core.el b/core/core.el index 410067e9e..9ef4927ce 100644 --- a/core/core.el +++ b/core/core.el @@ -300,7 +300,7 @@ original value of `symbol-file'." ;; Don't garbage collect to speed up minibuffer commands (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 () (setq gc-cons-threshold doom-gc-cons-threshold)) (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'." (when doom-debug-mode (message "Running doom hook: %s" hook)) - (condition-case e - (funcall hook) - ((debug error) - (signal 'doom-hook-error (list hook e)))) - ;; return nil so `run-hook-wrapped' won't short circuit - nil) + (let ((gc-cons-threshold doom-gc-cons-upper-limit)) + (condition-case e + (funcall hook) + ((debug error) + (signal 'doom-hook-error (list hook e)))) + ;; return nil so `run-hook-wrapped' won't short circuit + nil)) (defun doom-ensure-same-emacs-version-p () "Check if the running version of Emacs has changed and set diff --git a/init.el b/init.el index e54173824..3529750bc 100644 --- a/init.el +++ b/init.el @@ -27,30 +27,38 @@ ;; ;;; License: MIT -(defvar doom-gc-cons-threshold (* 8 1024 1024) - "The default value to use for `gc-cons-threshold'.") +(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 268435456 ; 256mb + "The temporary value for `gc-cons-threshold' to defer it.") (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 ;; its memory threshold, temporarily and reset it later in ;; `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 ;; functions. You get a minor speed up by nooping this. - (setq file-name-handler-alist nil)) - -(defun doom|disable-startup-optimizations () - "Resets garbage collection settings to reasonable defaults (if you don't do -this, you'll get stuttering and random freezes) and resets -`file-name-handler-alist'." - (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) + (setq file-name-handler-alist nil) + ;; Restore these to their defaults later. Do it on an idle timer to defer the + ;; possible GC pause, and to give deferred packages the ability to take + ;; advantage of these optimizations. + (run-with-idle-timer 5 nil #'doom|restore-startup-optimizations) + (add-hook 'doom-reload-hook #'doom|restore-startup-optimizations)) ;; 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. (setq load-prefer-newer noninteractive) + ;; Let 'er rip! (require 'core (concat user-emacs-directory "core/core"))