The `move` function is very slow on some large cpp files
Describe the bug
The move function is very slow on some large cpp files. Not sure if it's a bug, but it should be an optimization option.
To Reproduce Steps to reproduce the behavior:
- Prepare a large cpp file. In my case it's a file of over 1k lines
- call goto_* function
Output of :checkhealth nvim-treesitter
Installation ~
- WARNING
tree-sitterexecutable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall) - OK
nodefound v20.11.0 (only needed for :TSInstallFromGrammar) - OK
gitexecutable found. - OK
ccexecutable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" } Version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 - OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
OS Info: { machine = "x86_64", release = "5.15.133.1-microsoft-standard-WSL2", sysname = "Linux", version = "#1 SMP Thu Oct 5 21:02:42 UTC 2023" } ~
Parser/Features H L F I J
- bash ✓ ✓ ✓ . ✓
- c ✓ ✓ ✓ ✓ ✓
- cmake ✓ . ✓ ✓ .
- cpp ✓ ✓ ✓ ✓ ✓
- json ✓ ✓ ✓ ✓ .
- lua ✓ ✓ ✓ ✓ ✓
- markdown ✓ . ✓ ✓ ✓
- markdown_inline ✓ . . . ✓
- python ✓ ✓ ✓ ✓ ✓
- query ✓ ✓ ✓ ✓ ✓
- regex ✓ . . . .
- sql ✓ . . ✓ ✓
- vim ✓ ✓ ✓ . ✓
- vimdoc ✓ . . . ✓
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections +) multiple parsers found, only one will be used x) errors found in the query, try to run :TSUpdate {lang} ~
Paste the output here
Output of nvim --version
NVIM v0.10.0-dev
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Additional context
Below is the result captured by the profiler, you can see that a single query takes close to 3s, which makes neovim appear unresponsive for 3s.
After more digging, I found that nvim-treesitter.query.find_best_match loops at least 2w+ times per execution, which I think may be the culprit for this issue.
I also encounter the same issue, hope this to be resovled.
FYI, anyone who meet the same issue may refer the workaround by @folke https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/util/plugin.lua