Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsp--fontlock-with-mode is slow with treesit #4358

Open
3 tasks done
scturtle opened this issue Mar 6, 2024 · 0 comments
Open
3 tasks done

lsp--fontlock-with-mode is slow with treesit #4358

scturtle opened this issue Mar 6, 2024 · 0 comments
Labels

Comments

@scturtle
Copy link
Contributor

scturtle commented Mar 6, 2024

Thank you for the bug report

  • I am using the latest version of lsp-mode related packages.
  • I checked FAQ and Troubleshooting sections
  • You may also try reproduce the issue using clean environment using the following command: M-x lsp-start-plain

Bug description

I've noticed that the lsp--fontlock-with-mode function seems to be slow when the built-in tree-sitter support (treesit) is automatically enabled. I suspect this is because the .so library is being loaded on every call. For instance, profiling shows it takes around 0.16 seconds to execute:

lsp--fontlock-with-mode 0.163621 s
lsp--fontlock-with-mode 0.162615 s
lsp--fontlock-with-mode 0.163193 s
lsp--fontlock-with-mode 0.163004 s
lsp--fontlock-with-mode 0.162281 s

But with treesit turned off, it only takes 0.002 seconds:

lsp--fontlock-with-mode 0.002005 s
lsp--fontlock-with-mode 0.002601 s
lsp--fontlock-with-mode 0.002055 s
lsp--fontlock-with-mode 0.002191 s
lsp--fontlock-with-mode 0.002485 s

Steps to reproduce

(let ((t1 (current-time)))
  (with-temp-buffer
    (c++-ts-mode)
    (font-lock-ensure))
  (float-time (time-since t1)))

Expected behavior

Fast hover as before with treesit.

Which Language Server did you use?

C++

OS

Linux

Error callstack

No response

Anything else?

My workaround:

;; HACK: `lsp--fontlock-with-mode' is SLOW with treesit
(advice-add #'lsp--render-string :filter-args
            (lambda (args) (if (string= (cadr args) "markdown") args
                             (list (concat "```" (cadr args) "\n" (car args) "\n" "```") "markdown"))))
@scturtle scturtle added the bug label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant