From: Dmitry Gutov <dgutov@yandex.ru>
To: Eli Zaretskii <eliz@gnu.org>
Cc: casouri@gmail.com, 60953@debbugs.gnu.org
Subject: bug#60953: The :match predicate with large regexp in tree-sitter font-lock seems inefficient
Date: Thu, 26 Jan 2023 22:46:30 +0200 [thread overview]
Message-ID: <1d7aaf56-6130-c0f0-446f-4bc2c5cafa28@yandex.ru> (raw)
In-Reply-To: <31559c1f-1a12-691d-3d03-f566019a0aab@yandex.ru>
[-- Attachment #1: Type: text/plain, Size: 596 bytes --]
On 26/01/2023 20:07, Dmitry Gutov wrote:
> One could hope to avoid recreating the list of predicates on every
> match, but that seems to be a limitation of the TS API:
> ts_query_predicates_for_pattern requires a second argument,
> match.pattern_index. Maybe we could memoize that, though?
Speaking of memoization, here is a POC patch.
It's a definite improvement: with the attached :match almost reaches the
performance of :pred. Not sure why it's still not faster, though.
(I also tried a more comprehensive memoization using a hash table, the
resulting performance was slightly worse.)
[-- Attachment #2: memoize_simple.diff --]
[-- Type: text/x-patch, Size: 1162 bytes --]
diff --git a/src/treesit.c b/src/treesit.c
index 917db582676..69f54976509 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -2722,6 +2722,7 @@ DEFUN ("treesit-query-capture",
bottleneck (98.4% of the running time spent on nconc). */
Lisp_Object result = Qnil;
Lisp_Object prev_result = result;
+ Lisp_Object predicates_for_0 = NULL;
while (ts_query_cursor_next_match (cursor, &match))
{
/* Record the checkpoint that we may roll back to. */
@@ -2750,9 +2751,18 @@ DEFUN ("treesit-query-capture",
result = Fcons (cap, result);
}
/* Get predicates. */
- Lisp_Object predicates
- = treesit_predicates_for_pattern (treesit_query,
- match.pattern_index);
+ Lisp_Object predicates;
+ if (match.pattern_index == 0)
+ {
+ if (predicates_for_0 == NULL)
+ predicates_for_0 = treesit_predicates_for_pattern (treesit_query, 0);
+
+ predicates = predicates_for_0;
+ }
+ else
+ {
+ predicates = treesit_predicates_for_pattern (treesit_query, match.pattern_index);
+ }
/* captures_lisp = Fnreverse (captures_lisp); */
struct capture_range captures_range = { result, prev_result };
prev parent reply other threads:[~2023-01-26 20:46 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-20 3:53 bug#60953: The :match predicate with large regexp in tree-sitter font-lock seems inefficient Dmitry Gutov
2023-01-24 4:04 ` Dmitry Gutov
2023-01-25 3:13 ` Yuan Fu
2023-01-25 3:48 ` Dmitry Gutov
2023-01-25 12:49 ` Eli Zaretskii
2023-01-25 23:21 ` Dmitry Gutov
2023-01-26 6:50 ` Eli Zaretskii
2023-01-26 7:17 ` Yuan Fu
2023-01-26 8:10 ` Eli Zaretskii
2023-01-26 17:15 ` Dmitry Gutov
2023-01-26 18:24 ` Eli Zaretskii
2023-01-26 19:35 ` Dmitry Gutov
2023-01-26 20:01 ` Eli Zaretskii
2023-01-26 21:26 ` Dmitry Gutov
2023-01-30 0:49 ` Dmitry Gutov
2023-01-30 14:06 ` Eli Zaretskii
2023-01-30 14:47 ` Dmitry Gutov
2023-01-30 15:08 ` Eli Zaretskii
2023-01-30 17:15 ` Dmitry Gutov
2023-01-30 17:49 ` Eli Zaretskii
2023-01-30 18:20 ` Dmitry Gutov
2023-01-30 18:42 ` Eli Zaretskii
2023-01-30 19:01 ` Dmitry Gutov
2023-01-30 19:05 ` Eli Zaretskii
2023-01-30 19:58 ` Dmitry Gutov
2023-01-30 23:57 ` Yuan Fu
2023-01-31 0:44 ` Dmitry Gutov
2023-01-31 3:23 ` Eli Zaretskii
2023-01-31 18:16 ` Dmitry Gutov
2023-02-01 2:39 ` Dmitry Gutov
2023-02-01 13:39 ` Eli Zaretskii
2023-02-01 15:13 ` Dmitry Gutov
2023-02-01 21:20 ` Dmitry Gutov
2023-02-02 2:16 ` Yuan Fu
2023-02-02 6:34 ` Eli Zaretskii
2023-02-02 12:12 ` Dmitry Gutov
2023-02-02 14:23 ` Eli Zaretskii
2023-02-02 17:03 ` Dmitry Gutov
2023-02-02 17:26 ` Eli Zaretskii
2023-02-02 17:53 ` Dmitry Gutov
2023-02-02 18:03 ` Eli Zaretskii
2023-02-02 19:44 ` Dmitry Gutov
2023-02-01 13:10 ` Eli Zaretskii
2023-02-01 15:15 ` Dmitry Gutov
2023-01-26 17:12 ` Dmitry Gutov
2023-01-26 18:07 ` Dmitry Gutov
2023-01-26 20:46 ` Dmitry Gutov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1d7aaf56-6130-c0f0-446f-4bc2c5cafa28@yandex.ru \
--to=dgutov@yandex.ru \
--cc=60953@debbugs.gnu.org \
--cc=casouri@gmail.com \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.