nvim-treesitter-textobjects icon indicating copy to clipboard operation
nvim-treesitter-textobjects copied to clipboard

The `move` function is very slow on some large cpp files

Open ngpong opened this issue 2 years ago • 2 comments

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:

  1. Prepare a large cpp file. In my case it's a file of over 1k lines
  2. call goto_* function

Output of :checkhealth nvim-treesitter

nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~

  • WARNING tree-sitter executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
  • OK node found v20.11.0 (only needed for :TSInstallFromGrammar)
  • OK git executable found.
  • OK cc executable 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.

1707037303769

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.

ngpong avatar Feb 04 '24 09:02 ngpong

I also encounter the same issue, hope this to be resovled.

emmett2020 avatar Feb 18 '24 14:02 emmett2020

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

emmett2020 avatar Feb 18 '24 14:02 emmett2020