Files
neovim/runtime/lua/vim
vanaigr 4b02916334 perf(treesitter): use child_containing_descendant() in has-ancestor? (#28512)
Problem: `has-ancestor?` is O(n²) for the depth of the tree since it iterates over each of the node's ancestors (bottom-up), and each ancestor takes O(n) time.
This happens because tree-sitter's nodes don't store their parent nodes, and the tree is searched (top-down) each time a new parent is requested.

Solution: Make use of new `ts_node_child_containing_descendant()` in tree-sitter v0.22.6 (which is now the minimum required version) to rewrite the `has-ancestor?` predicate in C to become O(n).

For a sample file, decreases the time taken by `has-ancestor?` from 360ms to 6ms.
2024-05-16 16:57:58 +02:00
..
2024-05-16 14:29:56 +08:00
2024-05-15 23:19:26 +02:00
2024-04-30 07:04:42 +08:00
2024-03-06 10:45:22 +00:00
2024-04-26 15:13:06 +01:00
2024-05-16 17:37:46 +08:00
2024-01-16 09:33:10 +00:00
2024-05-15 07:18:33 +08:00
2024-05-15 12:38:26 +01:00
2024-01-19 11:54:04 +00:00
2024-05-15 07:18:33 +08:00
2024-03-16 19:26:10 +00:00
2024-05-15 07:18:33 +08:00
2024-03-16 19:26:10 +00:00
2024-05-15 23:19:26 +02:00
2024-04-30 07:04:42 +08:00
2024-03-16 19:26:10 +00:00
2024-03-09 11:21:55 +00:00