elixir-lang / tree-sitter-elixir

Elixir grammar for tree-sitter
https://elixir-lang.org/tree-sitter-elixir
Apache License 2.0
249 stars 25 forks source link

Poor performance on small file #21

Closed Wilfred closed 2 years ago

Wilfred commented 2 years ago

I recently ported difftastic to use this parser rather than https://github.com/ananthakumaran/tree-sitter-elixir.

https://gist.github.com/gausby/7b31d00bea9e97cf416e parses correctly, but it takes ~6 seconds to parse on my machine. This is an improvement over the previous parser (which is either looping or taking much longer -- I gave up after 5 minutes), but presumably a 48 line file should be faster than this?

jonatanklosko commented 2 years ago

Parsing the file is actually very fast:

➜  tree-sitter-elixir git:(main) npx tree-sitter parse --quiet --time tmp/bottles.ex
tmp/bottles.ex  0 ms

In fact, parsing the whole elixir-lang/elixir codebase takes ~2.1s for me :)

So the performance issues are rather related to how you use the AST, most likely queries. There has been a regression and then a fix in recent tree-sitter versions, see the discussion in https://github.com/nvim-treesitter/nvim-treesitter/issues/1957 and https://github.com/tree-sitter/tree-sitter/issues/1510, maybe it helps.

If I miss anything, please let me know!

Wilfred commented 2 years ago

Wow, thanks for the speedy response!

Yeah, it looks like https://github.com/tree-sitter/tree-sitter/issues/1510 is the culprit. I might downgrade to tree-sitter 0.19 until the fix is released.