From b656e68bc3050fb15eb64f4902bbcdae536560d6 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 16 Jun 2018 11:38:19 +0200 Subject: [PATCH] Move startup optimization to early-init Also load early-init from init if early-init-file isn't bound. This improves startup a modest 3-5% for Emacs 27 users. --- core/core-ui.el | 3 --- early-init.el | 51 ++++++++++++++++++++++++++++++++++++++----------- init.el | 39 ++----------------------------------- 3 files changed, 42 insertions(+), 51 deletions(-) diff --git a/core/core-ui.el b/core/core-ui.el index fb297391b..09eb5e883 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -609,9 +609,6 @@ frame's window-system, the theme will be reloaded.") (setq frame-title-format '("%b – Doom Emacs")) ;; draw me like one of your French editors (tooltip-mode -1) ; relegate tooltips to echo area only -(menu-bar-mode -1) -(if (fboundp 'tool-bar-mode) (tool-bar-mode -1)) -(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1)) ;; prompts the user for confirmation when deleting a non-empty frame (define-key global-map [remap delete-frame] #'doom/delete-frame) diff --git a/early-init.el b/early-init.el index e47330734..af00a89e5 100644 --- a/early-init.el +++ b/early-init.el @@ -1,18 +1,47 @@ ;;; early-init.el -*- lexical-binding: t; -*- ;; Emacs HEAD (27+) introduces early-init.el, which is run before init.el, -;; before most of its package and UI initialization happens. We can use this -;; opportunity to cull parts of the startup process early. +;; before package and UI initialization happens. We can use this opportunity to +;; cull parts of the startup process early and optimize Emacs startup ASAP. -;; Package initialize occurs automatically, before `user-init-file' is loaded, -;; but after `early-init-file'. Doom handles package initialization, so we must -;; prevent Emacs from doing it early! -(setq package-enable-at-startup nil) +(unless noninteractive + (defvar doom--file-name-handler-alist + file-name-handler-alist) + (unless after-init-time + ;; A big contributor to long startup times is the garbage collector, so we + ;; up its memory threshold, temporarily and reset it later in + ;; `doom|finalize'. + (setq gc-cons-threshold 402653184 + gc-cons-percentage 1.0 + ;; consulted on every `require', `load' and various file reading + ;; functions. You get a minor speed up by nooping this. + file-name-handler-alist nil)) -;; Faster to disable these here (before they've been initialized) -(setq tool-bar-mode nil - menu-bar-mode nil - scroll-bar-mode nil) -(modify-all-frames-parameters '((vertical-scroll-bars))) + (defun doom|finalize () + "Resets garbage collection settings to reasonable defaults (if you don't do +this, you'll get stuttering and random freezes) and resets +`file-name-handler-alist'." + (setq file-name-handler-alist doom--file-name-handler-alist + gc-cons-threshold 16777216 + gc-cons-percentage 0.15)) + + (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 +(setq user-emacs-directory (file-name-directory load-file-name) + ;; In noninteractive sessions, we hope that non-byte-compiled files will + ;; take precedence over byte-compiled ones, however, if you're getting odd + ;; recursive load errors, it may help to set this to nil. + load-prefer-newer noninteractive + ;; Package initialize occurs automatically, before `user-init-file' is + ;; loaded, but after `early-init-file'. Doom handles package + ;; initialization, so we must prevent Emacs from doing it early! + package-enable-at-startup nil) + +;; Prevent the glimpse of un-styled Emacs by setting these early. +(if (fboundp 'tool-bar-mode) (tool-bar-mode -1)) +(if (fboundp 'menu-bar-mode) (menu-bar-mode -1)) +(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1)) ;; TODO Once Emacs 27 hits stable, perhaps replace init.el with early-init.el diff --git a/init.el b/init.el index 68af9def2..ac0ca2237 100644 --- a/init.el +++ b/init.el @@ -27,42 +27,7 @@ ;; ;;; License: MIT -;; Ensure Doom is always running out of this file's directory -(setq user-emacs-directory (file-name-directory load-file-name) - load-prefer-newer noninteractive) - - -;; -;; Optimize startup -;; - -(unless noninteractive - (defvar doom--file-name-handler-alist - file-name-handler-alist) - (unless after-init-time - ;; A big contributor to long startup times is the garbage collector, so we - ;; up its memory threshold, temporarily and reset it later in - ;; `doom|finalize'. - (setq gc-cons-threshold 402653184 - gc-cons-percentage 1.0 - ;; consulted on every `require', `load' and various file reading - ;; functions. You get a minor speed up by nooping this. - file-name-handler-alist nil)) - - (defun doom|finalize () - "Resets garbage collection settings to reasonable defaults (if you don't do -this, you'll get stuttering and random freezes) and resets -`file-name-handler-alist'." - (setq file-name-handler-alist doom--file-name-handler-alist - gc-cons-threshold 16777216 - gc-cons-percentage 0.2)) - - (add-hook 'emacs-startup-hook #'doom|finalize) - (add-hook 'doom-reload-hook #'doom|finalize)) - - -;; -;; Bootstrap Doom -;; +(unless (boundp 'early-init-file) + (load (concat (file-name-directory load-file-name) "early-init"))) (require 'core (concat user-emacs-directory "core/core"))