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.)