Investigating an issue where Emacs freezes when viewing some Linux kernel source files.
I have an iMac as my main desktop computer and I am a heavy Emacs user. I do a lot of work with the Linux kernel which I do remotely on a Linux PC and I use Eglot with the clangd language server over TRAMP. I am mostly very happy with this setup, except for the occasional file that causes frequent freezes in Emacs.
An example "problem" file is include/uapi/linux/nl80211.h
which has long, heavily documented,
definitions such as enum nl80211_commands
. Whenever the cursor lands on a line within the
enum definition, Emacs freezes for a few seconds.
I used the built-in profiler to investigate the cause:
M-x profiler-start
# move to problem location and wait for duration of freeze
M-x profiler-report
Here's the CPU profile sample that shows the root cause:
3364 96% - timer-event-handler 3363 96% - apply 3286 94% - #<byte-code-function FD9> 3286 94% - jsonrpc-connection-receive 3285 94% - jsonrpc--continue 3285 94% - #<byte-code-function 215> 3285 94% - eglot--hover-info 3285 94% - mapconcat 3285 94% - eglot--format-markup 3282 94% - font-lock-ensure 3282 94% - #<byte-code-function CE1> 3282 94% - font-lock-fontify-region 3282 94% - font-lock-default-fontify-region 3281 94% - font-lock-fontify-keywords-region 3276 94% - markdown-match-italic 1636 46% - markdown-inline-code-at-pos-p 1636 46% - markdown-inline-code-at-pos 1501 43% - markdown-match-code 1501 43% - markdown-search-until-condition 1501 43% - apply 1501 43% re-search-forward 102 2% + markdown-beginning-of-text-block 33 0% + markdown-end-of-text-block 1631 46% - markdown-inline-code-at-pos 1504 43% - markdown-match-code 1504 43% - markdown-search-until-condition 1504 43% - apply 1504 43% re-search-forward 113 3% + markdown-beginning-of-text-block 13 0% + markdown-end-of-text-block 4 0% + markdown-match-inline-generic 3 0% + markdown--gfm-markup-underscore-p 1 0% markdown-range-property-any 1 0% match-data
Eglot wants to display the language server provided hover information. It's the processing of hover info response that is causing a multi-second freeze in Emacs.
Until I get a chance to try and fix the problem, I can avoid it happening by disabling the
hoverProvider
LSP capability in Eglot:
(custom-set-variables
;; ...
'(eglot-ignored-server-capabilities '(:hoverProvider))
;; ...
)