|
From: | Dmitry Gutov |
Subject: | bug#60953: The :match predicate with large regexp in tree-sitter font-lock seems inefficient |
Date: | Wed, 25 Jan 2023 05:48:13 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 |
On 25/01/2023 05:13, Yuan Fu wrote:
FYI the predicates are not processed by tree-sitter, but by us. For example, the #equal predicate is handled by treesit_predicate_equal. For #match, right now we create a string with Fbuffer_substring and pass it to fast_string_match, so it definitely causes a lot of gc’s, as you observed.
Right.
We can probably match the regexp in-place, just limit the match to the range of the node.
That's what I tried to do in the patch attached to the first message: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60953#5
But the effect on performance was surprisingly hard to notice. It also broke the actual highlighting, but that's probably because the regexp uses anchors \` and \', which don't really work for fast_looking_at calls inside a buffer.
I also experimented with replacing the current buffer-substring+string-match-p scheme with looking-at. No difference in performance.
Reducing the size of the regexp, however, made a lot of difference. ruby-ts--builtin-methods is 721 characters long.
So my current hypothesis is that the extra GC is caused by copying the regexp string back and forth. Which seems a bit more difficult to avoid. But could be done if we replace that value with some indirection.
[Prev in Thread] | Current Thread | [Next in Thread] |