nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects
The `move` function is very slow on some large cpp files
Nobody has claimed this yet.
- Dominant language
- Tree-sitter Query
- Stars
- 2.8k
- Forks
- 271
- Avg merge
- 8d 8h
- Merged PRs (30d)
- 1
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the profiler result and inspect nvim-treesitter.query.find_best_match, which the issue identifies as looping at least 2w+ times per execution. Reproduce the delay by calling a goto_* function on a large C++ file, then verify that the query no longer makes Neovim unresponsive for several seconds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, lua
- Domain
- devtools, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100