From db19241936e56bb0f406f7c3a3602908967e4f77 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 21 Nov 2019 14:43:36 -0500 Subject: [PATCH] Use gcmh package to manage adjust GC interactively --- core/autoload/debug.el | 3 ++- core/core-packages.el | 2 +- core/core.el | 46 +++++++++++++----------------------------- 3 files changed, 17 insertions(+), 34 deletions(-) diff --git a/core/autoload/debug.el b/core/autoload/debug.el index 14ae8fc00..d08efec60 100644 --- a/core/autoload/debug.el +++ b/core/autoload/debug.el @@ -336,5 +336,6 @@ will be automatically appended to the result." (setq doom-debug-mode value debug-on-error value jka-compr-verbose value - lsp-log-io value) + lsp-log-io value + gcmh-verbose value) (message "Debug mode %s" (if value "on" "off")))) diff --git a/core/core-packages.el b/core/core-packages.el index fd5bb0a1a..02a30d3ca 100644 --- a/core/core-packages.el +++ b/core/core-packages.el @@ -43,7 +43,7 @@ package's name as a symbol, and whose CDR is the plist supplied to its `package!' declaration. Set by `doom-initialize-packages'.") -(defvar doom-core-packages '(straight use-package async) +(defvar doom-core-packages '(straight use-package async gcmh) "A list of packages that must be installed (and will be auto-installed if missing) and shouldn't be deleted.") diff --git a/core/core.el b/core/core.el index e01c7bd23..093efc1d3 100644 --- a/core/core.el +++ b/core/core.el @@ -25,6 +25,12 @@ ;; You get a minor speed up by nooping this. (setq file-name-handler-alist nil) +;; Restore `file-name-handler-alist', because it is needed for handling +;; encrypted or compressed files, among other things. +(defun doom-reset-file-handler-alist-h () + (setq file-name-handler-alist doom--initial-file-name-handler-alist)) +(add-hook 'emacs-startup-hook #'doom-reset-file-handler-alist-h) + ;; Load the bare necessities (require 'core-lib) @@ -49,10 +55,6 @@ DEBUG envvar will enable this at startup.") (defvar doom-interactive-mode (not noninteractive) "If non-nil, Emacs is in interactive mode.") -(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.") - ;;; Directories/files (defconst doom-emacs-dir (eval-when-compile (file-truename user-emacs-directory)) @@ -261,34 +263,14 @@ users).") (unless IS-MAC (setq command-line-ns-option-alist nil)) (unless IS-LINUX (setq command-line-x-option-alist nil)) -;; Restore `file-name-handler-alist' because it is necessary for handling -;; encrypted or compressed files, among other things. -(defun doom-restore-file-name-handler-alist-h () - (setq file-name-handler-alist doom--initial-file-name-handler-alist)) -(add-hook 'emacs-startup-hook #'doom-restore-file-name-handler-alist-h) - -;; To speed up minibuffer commands (like helm and ivy), we defer garbage -;; collection while the minibuffer is active. -(defun doom-defer-garbage-collection-h () - "Increase `gc-cons-threshold' to stave off garbage collection." - (setq gc-cons-threshold most-positive-fixnum)) - -(defun doom-restore-garbage-collection-h () - "Restore `gc-cons-threshold' to a reasonable value so the GC can do its job." - ;; Defer it so that commands launched immediately after will 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) - -;; Not restoring these to their defaults will cause stuttering/freezes. -(add-hook 'emacs-startup-hook #'doom-restore-garbage-collection-h) - -;; When Emacs loses focus seems like a great time to do some garbage collection -;; all sneaky breeky like, so we can return to a fresh(er) Emacs. -(add-hook 'focus-out-hook #'garbage-collect) +;; Adopt a sneaky garbage collection strategy of waiting until idle time to +;; collect and staving off the collector while the user is working. +(unless doom-interactive-mode + (add-transient-hook! 'pre-command-hook (gcmh-mode +1)) + (with-eval-after-load 'gcmh + (setq gcmh-idle-delay 10 + gcmh-verbose doom-debug-mode) + (add-hook 'focus-out-hook #'gcmh-idle-garbage-collect))) ;;