From 6b5f44817e93c2985f3ea32122f1dc0047054018 Mon Sep 17 00:00:00 2001 From: L Lllvvuu Date: Mon, 11 Sep 2023 23:15:24 -0700 Subject: [PATCH] fix(languagetree): remove double recursion in LanguageTree:parse `LanguageTree:parse` is recursive, and calls `LanguageTree:for_each_child`, which is also recursive. That means that, starting from the third level (child of child of root), nodes will be parsed twice. Which then means that if the tree is N layers deep, there will be ~2^N parses even if the branching factor is 1. Now, why was the tree deepening with each character inserted? And why did this only regress in #24647? These are mysteries for another time. Fixes: #25104 --- runtime/lua/vim/treesitter/languagetree.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua index e81778b269..3c60da7643 100644 --- a/runtime/lua/vim/treesitter/languagetree.lua +++ b/runtime/lua/vim/treesitter/languagetree.lua @@ -444,9 +444,9 @@ function LanguageTree:parse(range) range = range, }) - self:for_each_child(function(child) + for _, child in pairs(self._children) do child:parse(range) - end) + end return self._trees end