From b387c1abb2d8a2588a422104c56c858f6737c764 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Mon, 13 Jan 2020 19:07:01 -0500 Subject: [PATCH] Optimize init startup time --- emacs/init.org | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/emacs/init.org b/emacs/init.org index 4039c6e..715a8bc 100755 --- a/emacs/init.org +++ b/emacs/init.org @@ -10,7 +10,44 @@ Enables lexical binding for everything in init.el: ;;; -*- lexical-binding: t; -*- #+END_SRC -Variables: +** Garbage collection +Some GC tweaks [[https://github.com/hlissner/doom-emacs/blob/develop/docs/faq.org#how-does-doom-start-up-so-quickly]["borrowed" from Doom emacs]]. + +Turn off GC during init and restore it afterwards: +#+BEGIN_SRC emacs-lisp + (setq gc-cons-threshold most-positive-fixnum + gc-cons-percentage 0.6) + + (add-hook 'emacs-startup-hook + (lambda () + (setq gc-cons-threshold 16777216 + gc-cons-percentage 0.1))) +#+END_SRC + +Also suppress GC for 1 second after the minibuffer is active to avoid stuttering autocompletion and other GC hangups: +#+BEGIN_SRC emacs-lisp + (defun defer-garbage-collection () + (setq gc-cons-threshold most-positive-fixnum)) + + (defun restore-garbage-collection () + (run-at-time + 1 nil (lambda () (setq gc-cons-threshold 16777216)))) + + (add-hook 'minibuffer-setup-hook #'defer-garbage-collection) + (add-hook 'minibuffer-exit-hook #'restore-garbage-collection) +#+END_SRC + +** Unset file-handler-alist during initialization +Another optimization from [[https://github.com/hlissner/doom-emacs/blob/develop/docs/faq.org#how-does-doom-start-up-so-quickly][Doom Emacs]]. +#+BEGIN_SRC emacs-lisp + (defvar file-name-handler-alist-backup file-name-handler-alist) + (setq file-name-handler-alist nil) + (add-hook 'emacs-startup-hook + (lambda () + (setq file-name-handler-alist file-name-handler-alist-backup))) +#+END_SRC + +** Variables #+BEGIN_SRC emacs-lisp (setq vc-follow-symlinks t) #+END_SRC @@ -1745,17 +1782,17 @@ Integrate Google calendar with org-mode: * Mode line * UI Get rid of the janky buttons: -#+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp :tangle ~/.emacs.d/early-init.el (tool-bar-mode -1) #+END_SRC And the menu bar: -#+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp :tangle ~/.emacs.d/early-init.el (menu-bar-mode -1) #+END_SRC And the ugly scroll bars: -#+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp :tangle ~/.emacs.d/early-init.el (set-scroll-bar-mode nil) #+END_SRC