Refactor gc optimizations on startup

Slightly smaller default gc-cons-threshold (and default
gc-cons-percentage), for less stuttering, and use most-postive-fixnum as
a ceiling.
This commit is contained in:
Henrik Lissner 2018-09-02 17:28:04 +02:00
parent 3d5c8ba279
commit 31bcac9a1e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

39
init.el
View file

@ -27,35 +27,38 @@
;; ;;
;;; License: MIT ;;; License: MIT
(defvar doom-gc-cons-threshold (* 8 1024 1024)
"The default value to use for `gc-cons-threshold'.")
(defvar doom--file-name-handler-alist file-name-handler-alist) (defvar doom--file-name-handler-alist file-name-handler-alist)
(unless after-init-time (unless after-init-time
;; A big contributor to long startup times is the garbage collector, so we ;; A big contributor to long startup times is the garbage collector, so we up
;; up its memory threshold, temporarily and reset it later in ;; its memory threshold, temporarily and reset it later in
;; `doom|finalize'. ;; `doom|disable-startup-optimizations'.
(setq gc-cons-threshold 402653184 (setq gc-cons-threshold most-positive-fixnum)
gc-cons-percentage 1.0 ;; This is consulted on every `require', `load' and various file reading
;; consulted on every `require', `load' and various file reading
;; functions. You get a minor speed up by nooping this. ;; functions. You get a minor speed up by nooping this.
file-name-handler-alist nil)) (setq file-name-handler-alist nil))
(defun doom|finalize () (defun doom|disable-startup-optimizations ()
"Resets garbage collection settings to reasonable defaults (if you don't do "Resets garbage collection settings to reasonable defaults (if you don't do
this, you'll get stuttering and random freezes) and resets this, you'll get stuttering and random freezes) and resets
`file-name-handler-alist'." `file-name-handler-alist'."
(setq file-name-handler-alist doom--file-name-handler-alist (setq file-name-handler-alist doom--file-name-handler-alist
gc-cons-threshold 16777216 gc-cons-threshold doom-gc-cons-threshold)
gc-cons-percentage 0.15)) (makunbound 'doom--file-name-handler-alist))
(add-hook 'emacs-startup-hook #'doom|disable-startup-optimizations)
(add-hook 'doom-reload-hook #'doom|disable-startup-optimizations)
(add-hook 'emacs-startup-hook #'doom|finalize)
(add-hook 'doom-reload-hook #'doom|finalize)
;; Ensure Doom is always running out of this file's directory ;; Ensure Doom is always running out of this file's directory
(setq user-emacs-directory (file-name-directory load-file-name) (setq user-emacs-directory (file-name-directory load-file-name))
;; In noninteractive sessions, we hope that non-byte-compiled files will ;; In noninteractive sessions, we hope that non-byte-compiled files will take
;; take precedence over byte-compiled ones, however, if you're getting odd ;; precedence over byte-compiled ones, however, if you're getting odd recursive
;; recursive load errors, it may help to set this to nil. ;; load errors, it may help to set this to nil.
load-prefer-newer noninteractive) (setq load-prefer-newer noninteractive)
;; Let 'er rip! ;; Let 'er rip!
(require 'core (concat user-emacs-directory "core/core")) (require 'core (concat user-emacs-directory "core/core"))