From 7a4588722e7f8c6f5034468f882e2993dde3d7c4 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Tue, 20 Apr 2021 08:21:08 -0500 Subject: [PATCH] A lot of performance tweaks --- README.org | 96 +++++++++++++++++++++++++++++++++++++++++++++++------- init.el | 79 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 153 insertions(+), 22 deletions(-) diff --git a/README.org b/README.org index c89a9204..54d9cafd 100644 --- a/README.org +++ b/README.org @@ -29,7 +29,7 @@ - [[#elfeed][Elfeed]] - [[#bongo][Bongo]] - [[#transmission][Transmission]] - - [[#garbage-collection][Garbage Collection]] + - [[#performance][Performance]] - [[#early-init][Early Init]] * Init @@ -103,6 +103,23 @@ Then let's make sure line-numbers are relative and on. And let's turn on visual- (global-visual-line-mode +1) #+end_src +Here are some ui changes I pulled from Doom Emacs +#+begin_src emacs-lisp + +;; always avoid GUI +(setq use-dialog-box nil) +;; Don't display floating tooltips; display their contents in the echo-area, +;; because native tooltips are ugly. +(when (bound-and-true-p tooltip-mode) + (tooltip-mode -1)) +;; ...especially on linux +(setq x-gtk-use-system-tooltips nil) + + ;; Favor vertical splits over horizontal ones. Screens are usually wide. +(setq split-width-threshold 160 + split-height-threshold nil) +#+end_src + Let's make doc-view better #+begin_src emacs-lisp (setq doc-view-resolution 192) @@ -120,6 +137,7 @@ Let's also turn on =recentf-mode=. ** Let's bootstrap straight.el #+begin_src emacs-lisp (setq straight-fix-org t) +(setq straight-check-for-modifications '(check-on-save find-when-checking)) (defvar bootstrap-version) (let ((bootstrap-file (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) @@ -332,7 +350,7 @@ This evil-collection package includes a lot of other evil based things. ** Undo-Tree #+begin_src emacs-lisp (use-package undo-tree - :defer 1 + :after evil :config (global-undo-tree-mode +1) :general @@ -564,7 +582,10 @@ Ace link provides an avy like search for links. Upon using the keybindings prese ** Help #+begin_src emacs-lisp (use-package helpful - :commands (helpful-callable helpful-variable helpful-command helpful-key)) + :commands (helpful-callable helpful-variable helpful-command helpful-key) + :general + (general-def 'normal 'helpful-mode-map + "q" 'chris/kill-buffer-frame)) #+end_src ** Format @@ -1478,7 +1499,7 @@ Let's add our own eshell prompt. and set the password cache to a significantly h :keymaps 'override "oe" 'eshell) (general-def '(normal insert) eshell-mode-map - "C-d" 'kill-buffer-and-window)) + "C-d" 'chris/kill-buffer-frame)) #+end_src ** Sly @@ -1512,13 +1533,22 @@ Let's use pdf-tools for a lot better interaction with pdfs. #+begin_src emacs-lisp (setq display-buffer-alist '(("\\*e?shell\\*" - (display-buffer--maybe-pop-up-frame-or-window) - (window-width . 0.4) - (side . bottom)) + (display-buffer-pop-up-frame)) + ("*helpful*" + (display-buffer-pop-up-frame)) + ("*elfeed-entry*" + (display-buffer-pop-up-frame)) ("*Bongo-Elfeed Queue*" - (display-buffer-in-side-window) - (window-height . 0.25) - (side . bottom)))) + (display-buffer-pop-up-frame)))) +#+end_src + +Since I like to make my window manager handle a lot of the window management, I will create a helper function for closing windows. +#+begin_src emacs-lisp +(defun chris/kill-buffer-frame () + "Kills the active buffer and frame" + (interactive) + (kill-this-buffer) + (delete-frame)) #+end_src ** Elfeed @@ -1658,14 +1688,56 @@ I use transmission on a server to manage my torrents "ot" 'transmission)) #+end_src -** Garbage Collection +** Performance +Here we have a bunch of performance tweaks +#+begin_src emacs-lisp +;; Reduce rendering/line scan work for Emacs by not rendering cursors or regions +;; in non-focused windows. +(setq-default cursor-in-non-selected-windows nil) +(setq highlight-nonselected-windows nil) + +;; More performant rapid scrolling over unfontified regions. May cause brief +;; spells of inaccurate syntax highlighting right after scrolling, which should +;; quickly self-correct. +(setq fast-but-imprecise-scrolling t) + +;; Don't ping things that look like domain names. +(setq ffap-machine-p-known 'reject) + +;; Emacs "updates" its ui more often than it needs to, so we slow it down +;; slightly from 0.5s: +(setq idle-update-delay 1.0) + +;; Font compacting can be terribly expensive, especially for rendering icon +;; fonts on Windows. Whether disabling it has a notable affect on Linux and Mac +;; hasn't been determined, but we inhibit it there anyway. This increases memory +;; usage, however! +;; (setq inhibit-compacting-font-caches t) + +;; Introduced in Emacs HEAD (b2f8c9f), this inhibits fontification while +;; receiving input, which should help with performance while scrolling. +(setq redisplay-skip-fontification-on-input t) +#+end_src +*** Garbage Collection We set the =gc-cons-threshold= variable to really high, now lets set it back low to make sure emacs performs properly. #+begin_src emacs-lisp -(setq gc-cons-threshold 2000000) +(setq gc-cons-threshold (* 32 1024 1024)) (setq garbage-collection-messages nil) #+end_src +Let's also use an automatic garbage collector while idle to make better input. +#+begin_src emacs-lisp +(use-package gcmh + :ensure t + :init + (gcmh-mode) + :config + (setq gcmh-idle-delay 5 + gcmh-high-cons-threshold (* 128 1024 1024) ; 128mb + gcmh-verbose t)) +#+end_src + * Early Init :PROPERTIES: :header-args: emacs-lisp :tangle early-init.el diff --git a/init.el b/init.el index 6314b909..4dee9d2b 100644 --- a/init.el +++ b/init.el @@ -44,6 +44,19 @@ (add-hook 'prog-mode-hook (display-line-numbers-mode +1)) (global-visual-line-mode +1) +;; always avoid GUI +(setq use-dialog-box nil) +;; Don't display floating tooltips; display their contents in the echo-area, +;; because native tooltips are ugly. +(when (bound-and-true-p tooltip-mode) + (tooltip-mode -1)) +;; ...especially on linux +(setq x-gtk-use-system-tooltips nil) + + ;; Favor vertical splits over horizontal ones. Screens are usually wide. +(setq split-width-threshold 160 + split-height-threshold nil) + (setq doc-view-resolution 192) (global-set-key (kbd "") 'keyboard-escape-quit) @@ -51,6 +64,7 @@ (recentf-mode +1) (setq straight-fix-org t) +(setq straight-check-for-modifications '(check-on-save find-when-checking)) (defvar bootstrap-version) (let ((bootstrap-file (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) @@ -220,7 +234,7 @@ (global-evil-surround-mode +1)) (use-package undo-tree - :defer 1 + :after evil :config (global-undo-tree-mode +1) :general @@ -335,7 +349,10 @@ vertically." :after avy) (use-package helpful - :commands (helpful-callable helpful-variable helpful-command helpful-key)) + :commands (helpful-callable helpful-variable helpful-command helpful-key) + :general + (general-def 'normal 'helpful-mode-map + "q" 'chris/kill-buffer-frame)) (use-package format-all :config @@ -1121,7 +1138,7 @@ If on a: :keymaps 'override "oe" 'eshell) (general-def '(normal insert) eshell-mode-map - "C-d" 'kill-buffer-and-window)) + "C-d" 'chris/kill-buffer-frame)) (use-package sly :mode ("\\.lisp\\'" . sly-mode)) @@ -1141,13 +1158,19 @@ If on a: (setq display-buffer-alist '(("\\*e?shell\\*" - (display-buffer--maybe-pop-up-frame-or-window) - (window-width . 0.4) - (side . bottom)) + (display-buffer-pop-up-frame)) + ("*helpful*" + (display-buffer-pop-up-frame)) + ("*elfeed-entry*" + (display-buffer-pop-up-frame)) ("*Bongo-Elfeed Queue*" - (display-buffer-in-side-window) - (window-height . 0.25) - (side . bottom)))) + (display-buffer-pop-up-frame)))) + +(defun chris/kill-buffer-frame () + "Kills the active buffer and frame" + (interactive) + (kill-this-buffer) + (delete-frame)) (use-package elfeed :commands (elfeed) @@ -1274,5 +1297,41 @@ interfere with the default `bongo-playlist-buffer'." :keymaps 'override "ot" 'transmission)) -(setq gc-cons-threshold 2000000) +;; Reduce rendering/line scan work for Emacs by not rendering cursors or regions +;; in non-focused windows. +(setq-default cursor-in-non-selected-windows nil) +(setq highlight-nonselected-windows nil) + +;; More performant rapid scrolling over unfontified regions. May cause brief +;; spells of inaccurate syntax highlighting right after scrolling, which should +;; quickly self-correct. +(setq fast-but-imprecise-scrolling t) + +;; Don't ping things that look like domain names. +(setq ffap-machine-p-known 'reject) + +;; Emacs "updates" its ui more often than it needs to, so we slow it down +;; slightly from 0.5s: +(setq idle-update-delay 1.0) + +;; Font compacting can be terribly expensive, especially for rendering icon +;; fonts on Windows. Whether disabling it has a notable affect on Linux and Mac +;; hasn't been determined, but we inhibit it there anyway. This increases memory +;; usage, however! +;; (setq inhibit-compacting-font-caches t) + +;; Introduced in Emacs HEAD (b2f8c9f), this inhibits fontification while +;; receiving input, which should help with performance while scrolling. +(setq redisplay-skip-fontification-on-input t) + +(setq gc-cons-threshold (* 32 1024 1024)) (setq garbage-collection-messages nil) + +(use-package gcmh + :ensure t + :init + (gcmh-mode) + :config + (setq gcmh-idle-delay 5 + gcmh-high-cons-threshold (* 128 1024 1024) ; 128mb + gcmh-verbose t))