From e572ee5c708de4469d6d2da0abaedaae5b371956 Mon Sep 17 00:00:00 2001 From: Vedang Manerikar <ved.manerikar@gmail.com> Date: Mon, 18 Nov 2024 19:58:26 +0530 Subject: [PATCH] Reset garbage collection defaults in startup hook Instead of using the gcmh package. --- early-init.el | 22 ++++++++++++++++++++-- unravel-emacs.org | 22 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/early-init.el b/early-init.el index 598588d..2c39e68 100644 --- a/early-init.el +++ b/early-init.el @@ -10,10 +10,28 @@ ;; A big contributor to startup times is garbage collection. ;; We up the gc threshold to temporarily prevent it from running, then -;; reset it later by enabling `gcmh-mode'. Not resetting it will cause -;; stuttering/freezes. +;; reset it later after startup is complete. Not resetting it will +;; cause stuttering/freezes. (setq gc-cons-threshold most-positive-fixnum) +(setq gc-cons-percentage 0.5) + +;; Same idea as above for the `file-name-handler-alist' and the +;; `vc-handled-backends' with regard to startup speed optimisation. +;; Here I am storing the default value with the intent of restoring it +;; via the `emacs-startup-hook'. +(defvar prot-emacs--file-name-handler-alist file-name-handler-alist) +(defvar prot-emacs--vc-handled-backends vc-handled-backends) + +(setq file-name-handler-alist nil + vc-handled-backends nil) + +(add-hook 'emacs-startup-hook + (lambda () + (setq gc-cons-threshold (* 1000 1000 8)) + (setq gc-cons-percentage 0.1) + (setq file-name-handler-alist prot-emacs--file-name-handler-alist) + (setq vc-handled-backends prot-emacs--vc-handled-backends))) ;; When both .el and .elc / .eln files are available, ;; load the latest one. diff --git a/unravel-emacs.org b/unravel-emacs.org index 2d1504a..1e4755b 100644 --- a/unravel-emacs.org +++ b/unravel-emacs.org @@ -99,10 +99,28 @@ by delegating to the =init.el ;; A big contributor to startup times is garbage collection. ;; We up the gc threshold to temporarily prevent it from running, then - ;; reset it later by enabling `gcmh-mode'. Not resetting it will cause - ;; stuttering/freezes. + ;; reset it later after startup is complete. Not resetting it will + ;; cause stuttering/freezes. (setq gc-cons-threshold most-positive-fixnum) + (setq gc-cons-percentage 0.5) + + ;; Same idea as above for the `file-name-handler-alist' and the + ;; `vc-handled-backends' with regard to startup speed optimisation. + ;; Here I am storing the default value with the intent of restoring it + ;; via the `emacs-startup-hook'. + (defvar prot-emacs--file-name-handler-alist file-name-handler-alist) + (defvar prot-emacs--vc-handled-backends vc-handled-backends) + + (setq file-name-handler-alist nil + vc-handled-backends nil) + + (add-hook 'emacs-startup-hook + (lambda () + (setq gc-cons-threshold (* 1000 1000 8)) + (setq gc-cons-percentage 0.1) + (setq file-name-handler-alist prot-emacs--file-name-handler-alist) + (setq vc-handled-backends prot-emacs--vc-handled-backends))) #+end_src ** If you have both .el and .elc files, load the newer one