Fix #4093: runaway gc-cons-threshold in lsp-mode

gc-cons-threshold was doubled every time an lsp-mode buffer was
opened (i.e. every time +lsp-optimization-mode was activated) causing
heavy freezes.
This commit is contained in:
Henrik Lissner 2020-10-15 02:18:00 -04:00
parent d85c7b857b
commit 1c7fd9c220
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -14,6 +14,7 @@ killing and opening many LSP/eglot-powered buffers.")
(defvar +lsp--default-read-process-output-max nil) (defvar +lsp--default-read-process-output-max nil)
(defvar +lsp--default-gcmh-high-cons-threshold nil) (defvar +lsp--default-gcmh-high-cons-threshold nil)
(defvar +lsp--optimization-init-p nil)
(define-minor-mode +lsp-optimization-mode (define-minor-mode +lsp-optimization-mode
"Deploys universal GC and IPC optimizations for `lsp-mode' and `eglot'." "Deploys universal GC and IPC optimizations for `lsp-mode' and `eglot'."
@ -21,21 +22,25 @@ killing and opening many LSP/eglot-powered buffers.")
:init-value nil :init-value nil
(if (not +lsp-optimization-mode) (if (not +lsp-optimization-mode)
(setq-default read-process-output-max +lsp--default-read-process-output-max (setq-default read-process-output-max +lsp--default-read-process-output-max
gcmh-high-cons-threshold +lsp--default-gcmh-high-cons-threshold) gcmh-high-cons-threshold +lsp--default-gcmh-high-cons-threshold
(setq +lsp--default-read-process-output-max +lsp--optimization-init-p nil)
(default-value 'read-process-output-max) ;; Only apply these settings once!
+lsp--default-gcmh-high-cons-threshold (unless +lsp--optimization-init-p
(default-value 'gcmh-high-cons-threshold)) (setq +lsp--default-read-process-output-max
;; `read-process-output-max' is only available on recent development (default-value 'read-process-output-max)
;; builds of Emacs 27 and above. +lsp--default-gcmh-high-cons-threshold
(setq-default read-process-output-max (* 1024 1024)) (default-value 'gcmh-high-cons-threshold))
;; REVIEW LSP causes a lot of allocations, with or without Emacs 27+'s ;; `read-process-output-max' is only available on recent development
;; native JSON library, so we up the GC threshold to stave off ;; builds of Emacs 27 and above.
;; GC-induced slowdowns/freezes. Doom uses `gcmh' to enforce its (setq-default read-process-output-max (* 1024 1024))
;; GC strategy, so we modify its variables rather than ;; REVIEW LSP causes a lot of allocations, with or without Emacs 27+'s
;; `gc-cons-threshold' directly. ;; native JSON library, so we up the GC threshold to stave off
(setq-default gcmh-high-cons-threshold (* 2 +lsp--default-gcmh-high-cons-threshold))) ;; GC-induced slowdowns/freezes. Doom uses `gcmh' to enforce its
(gcmh-set-high-threshold)) ;; GC strategy, so we modify its variables rather than
;; `gc-cons-threshold' directly.
(setq-default gcmh-high-cons-threshold (* 2 +lsp--default-gcmh-high-cons-threshold))
(gcmh-set-high-threshold)
(setq +lsp--optimization-init-p t))))
;; ;;