perf: gc-cons-percentage = 1.0 during startup

This commit is contained in:
Henrik Lissner 2026-03-27 06:16:27 -04:00
parent 0365c1a916
commit 7a068accbf
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 12 additions and 10 deletions

View file

@ -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

View file

@ -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)