From 586aa741df66070ebda5882cdc08dff6fa7bd848 Mon Sep 17 00:00:00 2001 From: laurensmiers Date: Mon, 20 Apr 2020 14:07:56 +0200 Subject: [PATCH] Fix lag in LSP mode due to garbage collection Used profiler to determine more than 80% of time was spent in garbage collection... Lowering the value back to the default fixes the lag. --- config.org | 24 ++++++++++++++++++------ init.el | 19 +++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/config.org b/config.org index d7d7a2d..4c561f7 100644 --- a/config.org +++ b/config.org @@ -228,15 +228,27 @@ so rebind it to something easy to remember. ** Garbage collection (gc) -I used to have the following enabled in my init to increase the gc threshold to speed-up emacs startup: -(stolen from [[http://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/]]) +A lot of articles/sites/posts/... about this: +- [[https://lists.gnu.org/archive/html/help-gnu-emacs/2007-06/msg00243.html ]] +- https://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/ +- ... + +This just contains some hooks to stop/enable the GC at critical moments. +I'm not touching the value except during startup. +If I leave it too high, I got a lot of lag when using LSP mode, so just leave it at the default value. + +I just 'Disable' GC in the minibuffer, I don't want lags/hangups/... in the minibuffer. #+BEGIN_SRC emacs-lisp -(setq gc-cons-threshold 100000000) -#+END_SRC +(defun my-minibuffer-setup-hook () + (setq gc-cons-threshold most-positive-fixnum)) -But according to this: [[https://lists.gnu.org/archive/html/help-gnu-emacs/2007-06/msg00243.html ]], -it is no longer necessary. But I found that I still have to do this to speed up emacs. +(defun my-minibuffer-exit-hook () + (setq gc-cons-threshold 800000)) + +(add-hook 'minibuffer-setup-hook #'my-minibuffer-setup-hook) +(add-hook 'minibuffer-exit-hook #'my-minibuffer-exit-hook) +#+END_SRC ** Yes-or-no questions diff --git a/init.el b/init.el index 309b8d2..d06699f 100644 --- a/init.el +++ b/init.el @@ -17,12 +17,19 @@ (package-refresh-contents) (package-install 'use-package)) -;; This is the actual config file. It is omitted if it doesn't exist so emacs won't refuse to launch. -(when (file-readable-p "~/.emacs.d/config.org") -(org-babel-load-file (expand-file-name "~/.emacs.d/config.org"))) +;;; Increase garbage collection threshold during init but leave it to the default value after +;;; There are a LOT of articles/sites/... discussing this: +;;; https://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/ +;;; https://jonnay.github.io/emagicians-starter-kit/Emagician-Base.html +;;; ... +(let ((gc-cons-threshold most-positive-fixnum)) + ;; This is the actual config file. It is omitted if it doesn't exist so emacs won't refuse to launch. + (when (file-readable-p "~/.emacs.d/config.org") + (org-babel-load-file (expand-file-name "~/.emacs.d/config.org"))) -;; If it exists, load some project-specific configurations. -(when (file-readable-p "~/.emacs.d/project.org") -(org-babel-load-file (expand-file-name "~/.emacs.d/project.org"))) + ;; If it exists, load some project-specific configurations. + (when (file-readable-p "~/.emacs.d/project.org") + (org-babel-load-file (expand-file-name "~/.emacs.d/project.org"))) +) (provide 'init)