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.
This commit is contained in:
laurensmiers 2020-04-20 14:07:56 +02:00
parent e9b132d7e8
commit 586aa741df
2 changed files with 31 additions and 12 deletions

View file

@ -228,15 +228,27 @@ so rebind it to something easy to remember.
** Garbage collection (gc) ** Garbage collection (gc)
I used to have the following enabled in my init to increase the gc threshold to speed-up emacs startup: A lot of articles/sites/posts/... about this:
(stolen from [[http://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/]]) - [[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 #+BEGIN_SRC emacs-lisp
(setq gc-cons-threshold 100000000) (defun my-minibuffer-setup-hook ()
#+END_SRC (setq gc-cons-threshold most-positive-fixnum))
But according to this: [[https://lists.gnu.org/archive/html/help-gnu-emacs/2007-06/msg00243.html ]], (defun my-minibuffer-exit-hook ()
it is no longer necessary. But I found that I still have to do this to speed up emacs. (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 ** Yes-or-no questions

19
init.el
View file

@ -17,12 +17,19 @@
(package-refresh-contents) (package-refresh-contents)
(package-install 'use-package)) (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. ;;; Increase garbage collection threshold during init but leave it to the default value after
(when (file-readable-p "~/.emacs.d/config.org") ;;; There are a LOT of articles/sites/... discussing this:
(org-babel-load-file (expand-file-name "~/.emacs.d/config.org"))) ;;; 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. ;; If it exists, load some project-specific configurations.
(when (file-readable-p "~/.emacs.d/project.org") (when (file-readable-p "~/.emacs.d/project.org")
(org-babel-load-file (expand-file-name "~/.emacs.d/project.org"))) (org-babel-load-file (expand-file-name "~/.emacs.d/project.org")))
)
(provide 'init) (provide 'init)