lsp-ui icon indicating copy to clipboard operation
lsp-ui copied to clipboard

poor cursor responsiveness with lsp-ui enabled on macOS with 4k displays

Open strobe opened this issue 3 years ago • 3 comments

Caret movement very slow (especially horizontal) on any file with 'lsp-ui' enabled (GUI mode)(it feels like low key repeat rate), enabling 'fundamental-mode' fixed that behavior.

I'm struggling with this bug for a while but I admit that is something which hard to investigate for me. So in summary I don't have yet specific bug report but I looking for ideas on how I can locate the source of this specific issue to report it with all required details.

It's reproducible on my machine (Macbook pro-2019 (i9) with two 4k external displays connected via Thunderbold 3 -> DP adapter and lid closed) with 'lsp-mode', 'lsp-metals', 'lsp-ui' enabled (set up for Scala). And I don't have this issue without external displays and on another hp envy Linux laptop with a build-in 4k display.

I tested it on 'emacs-plus' (with different builds 27, 28, and 28 with 'gccemacs') and on 'emacs-mac' ('emacs-mac' seems less affected than 'emacs-plus'). I also tested it with few emacs configs: simple config, doom based, prelude based.

It obviously somehow connected to rendering because basically if I have a small emacs window opened (app window not emacs window) on 4k display the issue doesn't happen but if I fill the whole display with emacs it slows down dramatically. So basically the size of the emacs app window connected directly to this behavior. (GPU history not showing huge load and CPU also seems not to issue here) (Also, if I open 3 windows (1/3 display size each) with different frames behavior be the same) (and of course 'emacs -Q' blazing fast on same display).

Also, I thought that probably is connected to 'lsp-ui-doc-frame' and tried to tune stuff like 'lsp-ui-doc-delay' but it's not helpful.

In summary, if I have 'lsp-ui' disabled with the same configs issue doesn't happen in another case seems it not related to any explicitly used 'lsp-ui' features (emacs profiling not showing anything interesting here).

Also tried to configure this stuff as 'lsp-mode' doc says:

     (setq gc-cons-threshold 100000000) ;; 100mb
     (setq read-process-output-max (* 1024 1024)) ;; 1mb
     (setq lsp-idle-delay 0.500)
     (setq lsp-log-io nil)
     (setq lsp-completion-provider :capf)

(it also not addressed this issue)

strobe avatar Feb 08 '21 09:02 strobe

minimal config for reproducing that behavior via ENV HOME=./ emacs -Q -l init-lsp-ui-issue.el):

(require 'package)

;; Add melpa to your packages repositories
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)

(package-initialize)

;; Install use-package if not already installed
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(require 'use-package)

;; Enable defer and ensure by default for use-package
;; Keep auto-save/backup files separate from source code:  https://github.com/scalameta/metals/issues/1027
(setq use-package-always-defer t
      use-package-always-ensure t
      backup-directory-alist `((".*" . ,temporary-file-directory))
      auto-save-file-name-transforms `((".*" ,temporary-file-directory t)))

;; Enable scala-mode for highlighting, indentation and motion commands
(use-package scala-mode
  :interpreter
    ("scala" . scala-mode))

;; Enable sbt mode for executing sbt commands
(use-package sbt-mode
  :commands sbt-start sbt-command
  :config
  ;; WORKAROUND: https://github.com/ensime/emacs-sbt-mode/issues/31
  ;; allows using SPACE when in the minibuffer
  (substitute-key-definition
   'minibuffer-complete-word
   'self-insert-command
   minibuffer-local-completion-map)
   ;; sbt-supershell kills sbt-mode:  https://github.com/hvesalai/emacs-sbt-mode/issues/152
   (setq sbt:program-options '("-Dsbt.supershell=false"))
)

;; Enable nice rendering of diagnostics like compile errors.
(use-package flycheck
  :init (global-flycheck-mode))

(use-package company)

(use-package lsp-mode
  ;; Optional - enable lsp-mode automatically in scala files
  :hook  (scala-mode . lsp)
         (lsp-mode . lsp-lens-mode)
  :config (setq lsp-prefer-flymake nil)
          ;; perfomance tuning
          (setq gc-cons-threshold 100000000) ;; 100mb
          (setq read-process-output-max (* 1024 1024)) ;; 1mb
          (setq lsp-idle-delay 0.500)
          (setq lsp-log-io nil)
          (setq lsp-completion-provider :capf))

;; Add metals backend for lsp-mode
(use-package lsp-metals
  :config (setq lsp-metals-treeview-show-when-views-received t))

;; Enable nice rendering of documentation on hover
(use-package lsp-ui)

;; lsp-mode supports snippets, but in order for them to work you need to use yasnippet
;; If you don't want to use snippets set lsp-enable-snippet to nil in your lsp-mode settings
;;   to avoid odd behavior with snippets and indentation
(use-package yasnippet)

Disabling all lsp-ui modes actually solves it but removing from config is not because it could be activated automatically by lsp-mode.

Note:

  1. It may require increasing the key repeat rate on macOS to make it more visible:
defaults write -g InitialKeyRepeat -int 10 # normal minimum is 15 (225 ms)
defaults write -g KeyRepeat -int 1 # normal minimum is 2 (30 ms)
  1. in the terminal (iterm2) with '-nw' flags that doesn't happens

strobe avatar Feb 08 '21 17:02 strobe

profiler report example

- command-execute                                                 231  57%
 - call-interactively                                             231  57%
  - byte-code                                                     154  38%
   - read-extended-command                                        154  38%
    - completing-read                                             154  38%
     + completing-read-default                                    154  38%
  - funcall-interactively                                          77  19%
   - execute-extended-command                                      67  16%
    - sit-for                                                      61  15%
       redisplay                                                    8   1%
    + command-execute                                               5   1%
   + next-line                                                      8   1%
   + previous-line                                                  2   0%
- lsp-ui-doc--make-request                                         77  19%
 - lsp-ui-doc--hide-frame                                          69  17%
    lsp-ui-doc--get-frame                                           2   0%
 + run-with-idle-timer                                              3   0%
 + symbol-at-point                                                  1   0%
 + bounds-of-thing-at-point                                         1   0%
   cancel-timer                                                     1   0%
+ #<compiled 0x1ff3d3e16f61>                                       30   7%
+ redisplay_internal (C function)                                  19   4%
+ timer-event-handler                                              17   4%
  posframe-run-hidehandler                                         10   2%
+ ...                                                               9   2%
+ eldoc-pre-command-refresh-echo-area                               7   1%
+ lsp-ui-sideline                                                   2   0%

strobe avatar Feb 08 '21 17:02 strobe

I think this is duplicate of #613?

jcs090218 avatar Aug 06 '21 12:08 jcs090218