From 7a068accbfedf2eda8bf4ea7dbd8317b742984c1 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 27 Mar 2026 06:16:27 -0400 Subject: [PATCH] perf: gc-cons-percentage = 1.0 during startup --- early-init.el | 8 ++++---- lisp/doom.el | 14 ++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/early-init.el b/early-init.el index 3abe4dac1..1c8cb29d8 100644 --- a/early-init.el +++ b/early-init.el @@ -28,13 +28,12 @@ ;; PERF: Garbage collection is a big contributor to startup times in both ;; interactive and CLI sessions, so I defer it. +(setq gc-cons-percentage 1.0) (if noninteractive ; in CLI sessions ;; PERF: GC deferral is less important in the CLI, but still helps script ;; startup times. Just don't set it too high to avoid runaway memory usage ;; in long-running elisp shell scripts. - (setq gc-cons-threshold 134217728 ; 128mb - ;; Backported from 29 (see emacs-mirror/emacs@73a384a98698) - gc-cons-percentage 1.0) + (setq gc-cons-threshold 134217728) ; 128mb ;; PERF: Doom relies on `gcmh-mode' to reset this while the user is idle, so I ;; effectively disable GC during startup. DON'T COPY THIS BLINDLY! If it's ;; not reset later there will be stuttering, freezes, and crashes. @@ -137,7 +136,8 @@ ;; to `most-positive-fixnum' is dangerous if downstream does not ;; reset it later to something reasonable, so I use 16mb as a best ;; fit guess. It's better than Emacs' 80kb default. - (setq gc-cons-threshold (* 16 1024 1024)) + (setq gc-cons-threshold (* 16 1024 1024) + gc-cons-percentage 0.1) nil)) ;; Sets up Doom (particularly `doom-profile') for the session ahead. This ;; loads the profile's init file, if it's available. In interactive diff --git a/lisp/doom.el b/lisp/doom.el index 4e6c976c4..af4efd053 100644 --- a/lisp/doom.el +++ b/lisp/doom.el @@ -902,12 +902,14 @@ Triggers `doom-after-init-hook' and sets `doom-init-time.'" (setq doom-init-time (float-time (time-subtract (current-time) before-init-time))) (doom-run-hooks 'doom-after-init-hook) - ;; If `gc-cons-threshold' hasn't been reset at this point, we reset it by - ;; force (without overwriting `gcmh' or the user's config). If this isn't - ;; done, this session will be prone to freezing and crashes. This also - ;; handles the case where the user has `gcmh' disabled. - (when (eq (default-value 'gc-cons-threshold) most-positive-fixnum) - (setq-default gc-cons-threshold (* 16 1024 1024))) + ;; If `gc-cons-threshold' and `gc-cons-percentage' haven't been reset at + ;; this point, do it now (without overwriting `gcmh' or the user's config). + ;; If not done, the session may see freezing and crashes. Also handles the + ;; case where the user has `gcmh' disabled (e.g. users on the IGC branch). + (if (= (default-value 'gc-cons-threshold) most-positive-fixnum) + (setq-default gc-cons-threshold (* 16 1024 1024))) + (if (= (default-value 'gc-cons-percentage) 1.0) + (setq-default gc-cons-percentage 0.1)) t)) (provide 'doom)