From 1c7fd9c220b3a3cbe2295238f3a81e0453f7c3ee Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 15 Oct 2020 02:18:00 -0400 Subject: [PATCH] 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. --- modules/tools/lsp/config.el | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/modules/tools/lsp/config.el b/modules/tools/lsp/config.el index b446ada27..8cccbc0c0 100644 --- a/modules/tools/lsp/config.el +++ b/modules/tools/lsp/config.el @@ -14,6 +14,7 @@ killing and opening many LSP/eglot-powered buffers.") (defvar +lsp--default-read-process-output-max nil) (defvar +lsp--default-gcmh-high-cons-threshold nil) +(defvar +lsp--optimization-init-p nil) (define-minor-mode +lsp-optimization-mode "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 (if (not +lsp-optimization-mode) (setq-default read-process-output-max +lsp--default-read-process-output-max - gcmh-high-cons-threshold +lsp--default-gcmh-high-cons-threshold) - (setq +lsp--default-read-process-output-max - (default-value 'read-process-output-max) - +lsp--default-gcmh-high-cons-threshold - (default-value 'gcmh-high-cons-threshold)) - ;; `read-process-output-max' is only available on recent development - ;; builds of Emacs 27 and above. - (setq-default read-process-output-max (* 1024 1024)) - ;; REVIEW LSP causes a lot of allocations, with or without Emacs 27+'s - ;; native JSON library, so we up the GC threshold to stave off - ;; GC-induced slowdowns/freezes. Doom uses `gcmh' to enforce its - ;; 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)) + gcmh-high-cons-threshold +lsp--default-gcmh-high-cons-threshold + +lsp--optimization-init-p nil) + ;; Only apply these settings once! + (unless +lsp--optimization-init-p + (setq +lsp--default-read-process-output-max + (default-value 'read-process-output-max) + +lsp--default-gcmh-high-cons-threshold + (default-value 'gcmh-high-cons-threshold)) + ;; `read-process-output-max' is only available on recent development + ;; builds of Emacs 27 and above. + (setq-default read-process-output-max (* 1024 1024)) + ;; REVIEW LSP causes a lot of allocations, with or without Emacs 27+'s + ;; native JSON library, so we up the GC threshold to stave off + ;; GC-induced slowdowns/freezes. Doom uses `gcmh' to enforce its + ;; 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)))) ;;