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

Freeze in large C file with treesitter #302

Open
zeertzjq opened this issue Jul 5, 2023 · 6 comments
Open

Freeze in large C file with treesitter #302

zeertzjq opened this issue Jul 5, 2023 · 6 comments

Comments

@zeertzjq
Copy link
Contributor

zeertzjq commented Jul 5, 2023

Is your feature request related to a problem? Please describe.
When treesitter highlighting is enabled, vim-matchup unconditionally uses treesitter delim skip, which can be very slow. In some large C files this causes vim-matchup to freeze Nvim for seconds when moving cursor onto a curly brace, and the following change makes the lag disappear:

diff --git a/autoload/matchup/loader.vim b/autoload/matchup/loader.vim
index e78243b..b943f7a 100644
--- a/autoload/matchup/loader.vim
+++ b/autoload/matchup/loader.vim
@@ -58,12 +58,7 @@ function! matchup#loader#init_buffer() abort " {{{1
   let b:matchup_delim_re = s:init_delim_regexes()
 
   " process b:match_skip
-  if l:has_ts_hl
-    let b:matchup_delim_skip
-          \ = "matchup#ts_syntax#skip_expr(s:effline('.'),s:effcol('.'))"
-  else
     let b:matchup_delim_skip = s:init_delim_skip()
-  endif
 
   " enable matching engines
   let b:matchup_active_engines = {}

Describe the solution you'd like
Add an option to vim-matchup to disable treesitter delim skip.

@andymass
Copy link
Owner

andymass commented Jul 5, 2023

Because it uses the Treesitter AST, my expectation is matchup#ts_syntax#skip_expr would be very fast. (At least faster than vim syntax highlighting.) Maybe there is something wrong in the way it's computed or cached.

Can you provide a sample C file which has the issue?

@zeertzjq
Copy link
Contributor Author

zeertzjq commented Jul 5, 2023

src/nvim/regexp_nfa.c in Nvim source code.

@zeertzjq
Copy link
Contributor Author

zeertzjq commented Jul 5, 2023

I may have made a mistake when testing this. It seems that when I fully enable matchup treesitter support (matchup = { enable = true }), vim-matchup freezes Nvim every time viewport scrolls by a screen. However, if I disable that (matchup = { enable = false }), vim-matchup only freezes the first time I stop cursor on a curly brace and is fast afterwards. This is probably not needed then.

@zeertzjq zeertzjq closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2023
@andymass
Copy link
Owner

andymass commented Jul 5, 2023 via email

@andymass andymass reopened this Jul 5, 2023
@zeertzjq zeertzjq changed the title Allow disabling treesitter delim skip Freeze in large C file with treesitter Jul 6, 2023
@andymass
Copy link
Owner

andymass commented Jul 11, 2023

I see a huge amount of lag in regexp_nfa.c when scrolling but it doesn't seem to be caused by ts syntax skip but instead this call to get_active_nodes

local active_nodes, symbols = unpack(M.get_active_nodes(bufnr))

When I comment this line out the lag disappears. What I don't understand is that get_active_nodes is gated behind ts_utils.memoize_by_buf_tick

M.get_active_nodes = ts_utils.memoize_by_buf_tick(function(bufnr)

Yet when scrolling it seems to be called again and again, even if the buffer hasn't changed.

@3rd
Copy link

3rd commented Jul 24, 2023

Had this same issue but in Lua files, when moving cursor up/down and hitting a bracked it would freeze the editor for a bit (on a very beefy machine), fixed by disabling the plugin. Might be a Neovim issue, disabled Navic as well for the same reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants