From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#60953: The :match predicate with large regexp in tree-sitter font-lock seems inefficient Date: Mon, 30 Jan 2023 21:01:02 +0200 Message-ID: <19892f55-498e-1109-2229-2ddd984849a4@yandex.ru> References: <7624dddc-4600-9a03-ac8b-d3c9e0ab618c@yandex.ru> <04729838-b7d4-8a08-2b71-12536a28aebb@yandex.ru> <83wn5ag4nc.fsf@gnu.org> <01b5d074-fb12-6b1f-cbfb-5e759833b854@yandex.ru> <838rhpg57n.fsf@gnu.org> <5026D975-983F-4D18-8690-BE139C92825D@gmail.com> <83pmb1emxi.fsf@gnu.org> <6f318afc-ca71-8b7e-c822-52e6635b5718@yandex.ru> <83sffxcfxw.fsf@gnu.org> <83pmb1cbg5.fsf@gnu.org> <2da844d3-ea31-289e-2821-aa174e365ffd@yandex.ru> <6784f9e7-844b-374d-2a1e-8a61cebe0d7e@yandex.ru> <83zga03yne.fsf@gnu.org> <373a575f-c683-1581-c3e6-502e9897fb04@yandex.ru> <83mt603vrc.fsf@gnu.org> <83e58a1b-2e4a-356a-36d8-c756ff105b62@yandex.ru> <83bkmf52va.fsf@gnu.org> <33cad4c1-4af5-37bb-05bc-79a4d9c1a700@yandex.ru> <83wn533lut.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19256"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Cc: casouri@gmail.com, 60953@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 30 20:02:46 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pMZQT-0004md-L1 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 30 Jan 2023 20:02:45 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMZPp-00063S-5v; Mon, 30 Jan 2023 14:02:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMZPm-00062p-QT for bug-gnu-emacs@gnu.org; Mon, 30 Jan 2023 14:02:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pMZPm-0001np-5l for bug-gnu-emacs@gnu.org; Mon, 30 Jan 2023 14:02:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pMZPl-0003e7-Ve for bug-gnu-emacs@gnu.org; Mon, 30 Jan 2023 14:02:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 30 Jan 2023 19:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60953 X-GNU-PR-Package: emacs Original-Received: via spool by 60953-submit@debbugs.gnu.org id=B60953.167510527113951 (code B ref 60953); Mon, 30 Jan 2023 19:02:01 +0000 Original-Received: (at 60953) by debbugs.gnu.org; 30 Jan 2023 19:01:11 +0000 Original-Received: from localhost ([127.0.0.1]:50589 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pMZOw-0003cw-SG for submit@debbugs.gnu.org; Mon, 30 Jan 2023 14:01:11 -0500 Original-Received: from mail-ed1-f48.google.com ([209.85.208.48]:35592) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pMZOv-0003ci-Gu for 60953@debbugs.gnu.org; Mon, 30 Jan 2023 14:01:10 -0500 Original-Received: by mail-ed1-f48.google.com with SMTP id q19so2030682edd.2 for <60953@debbugs.gnu.org>; Mon, 30 Jan 2023 11:01:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=L2W4tBXaiW27sCnLUMSNyyCRdSO1nrUxaud8Rz75M+M=; b=OtvJIaeaEOtkMI6Rrv+pmMiW5OpMnkJEtpL2L/U8grqO1ItmXEMo09B7ZXaEv6vqcc rSzF1N3bNfgFHKQXt3QYYF3NiKKdb9RQpEmv2yzlP0Tz0cgm82dyXiis84Q4bl5zgcaY LPgeleoaAZ3NE03GQR27QyUwn0ItTgQgBXFBKrcQlF51QfzTBXLq1axFzxjSkifmgdoi tMLLIPmkU3E2reSfQjDLbHiK1sl51EMLreBOInvI/sYm3vuNrIWl44lPGYXubsdNfgRv wvL9d84Y9kIrEVjP67ou0kdPSQrfv3QISGfTl9EGzjQEkA+aOulmcHaTC5QVU/hwNzMb jLFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=L2W4tBXaiW27sCnLUMSNyyCRdSO1nrUxaud8Rz75M+M=; b=IHZpb1vRdGir6iXTBZ9bqNScc5FSIEVa+Ze+MyXqsIqf4Y1P+6kUkThTh9Z4XYCPRQ riWMG8jFDI472qR/YMUq8ZR6ESJ5gxVSejV4R0oJDMoJHmrrZQO+C1Evweh99V7myucA a9nc3WA1ii8MUUQdNBBK3zwfXKYz+sTS0gnAkH57bLBymLThGLLbh57mVd0rNHVZ47ag O8L6tVHQxbBBqYXgu+Z+TXU/1lVjmQa+RVgJ0Ff8mm8lYNWLe4edWMERdgh4luUm7dVi zWKiaVJUjBXtROmx0aAmiDEwlKl9tFjmeOoaBp+6MV0wt8AG3EAW8BQAant/Dxv8TnCP 5qsQ== X-Gm-Message-State: AO0yUKUP0ACHTBOfKXV3bNoz11cImS898dE4mFRBeJzsGGYs2Wv5f1Gg G35A78fUHhzssB2ozvR8SSU= X-Google-Smtp-Source: AK7set98emk4JfztjdjZ1Ra+mdf2j4T9oDUu4Z7Vq3CZ4CBNJmfaKqcA3F5HvVDtPcZ5GVYOY53mCA== X-Received: by 2002:a05:6402:4003:b0:4a2:2fa:ead4 with SMTP id d3-20020a056402400300b004a202faead4mr16462840eda.17.1675105263811; Mon, 30 Jan 2023 11:01:03 -0800 (PST) Original-Received: from [192.168.0.2] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id a16-20020aa7d910000000b00463bc1ddc76sm7131949edr.28.2023.01.30.11.01.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Jan 2023 11:01:03 -0800 (PST) Content-Language: en-US In-Reply-To: <83wn533lut.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:254472 Archived-At: On 30/01/2023 20:42, Eli Zaretskii wrote: >> Date: Mon, 30 Jan 2023 20:20:46 +0200 >> Cc: casouri@gmail.com, 60953@debbugs.gnu.org >> From: Dmitry Gutov >> >> On 30/01/2023 19:49, Eli Zaretskii wrote: >>>> Date: Mon, 30 Jan 2023 19:15:07 +0200 >>>> Cc: casouri@gmail.com, 60953@debbugs.gnu.org >>>> From: Dmitry Gutov >>>> >>>>> fast_looking_at already does an anchored match, so I'm not sure I >>>>> follow. I don't even understand why you need th \` part, when the >>>>> match will either always start from the first position or fail. >>>> >>>> The regexp might include the anchors, or it might not. >>>> >>>> It might also use a different anchor like ^ or $ or \b. >>> >>> OK, but it always goes only forward, so narrowing to the beginning >>> shouldn't be necessary. Right? >> >> Are you saying that fast_looking_at ("\\`", ...) will always succeed? >> >> And fast_looking_at ("^", ...), etc. > > For example, for "^", if you hint that it must look back to make sure > there's a newline there, then your narrowing will also prevent it from > doing that, right? fast_looking_at ("^", ...) succeeds inside a narrowing because it always succeeds at BOB. Even though there are no physical newlines before BOB. >>>> One possible alternative, I suppose, would be to create a raw pointer to >>>> a part of the buffer text and call re_search directly specifying the >>>> known length of the node in bytes. If buffer text is one contiguous >>>> region in memory, that is. >>> >>> It isn't, though: there's the gap. Which is why doing this is not >>> recommended; instead, use something like search_buffer_re, which >>> already handles this complication for you. (Except that >>> search_buffer_re is a static function, so only code in search.c can >>> use it. So you'd need to make it non-static.) >> >> Interesting. Does search_buffer_re match the \` anchor at POS and \' at >> LIM? IOW, does in treat the rest of the buffer as non-existing? Or could it? > > That is the low-level subroutine called by re-search-forward, so you > know the answers already, I think? IOW, that function behaves exactly > like re-search-forward in those situations. So, I suppose not? But that doesn't answer the question "Could it?".