From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#63225: Compiling regexp patterns (and REGEXP_CACHE_SIZE in search.c) Date: Tue, 2 May 2023 23:00:29 +0200 Message-ID: <37EED5F9-F1FE-46B6-B4FA-0B268B945123@gmail.com> References: <63882A45-BD02-40D5-92FA-70175267BA3B@acm.org> <874jou7lsf.fsf@localhost> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3651"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 63225@debbugs.gnu.org To: Ihor Radchenko Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 02 23:01:29 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 1ptx7o-0000nP-4X for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 May 2023 23:01:28 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ptx7T-00070m-6C; Tue, 02 May 2023 17:01:07 -0400 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 1ptx7O-0006yy-VR for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 17:01:03 -0400 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 1ptx7O-0005ni-NO for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 17:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ptx7O-0003SV-3I for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 17:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 02 May 2023 21:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63225 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 63225-submit@debbugs.gnu.org id=B63225.168306123913253 (code B ref 63225); Tue, 02 May 2023 21:01:02 +0000 Original-Received: (at 63225) by debbugs.gnu.org; 2 May 2023 21:00:39 +0000 Original-Received: from localhost ([127.0.0.1]:45141 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ptx71-0003Rf-Dm for submit@debbugs.gnu.org; Tue, 02 May 2023 17:00:39 -0400 Original-Received: from mail-lf1-f46.google.com ([209.85.167.46]:48531) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ptx6y-0003RP-UW for 63225@debbugs.gnu.org; Tue, 02 May 2023 17:00:38 -0400 Original-Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-4efe9a98736so4969080e87.1 for <63225@debbugs.gnu.org>; Tue, 02 May 2023 14:00:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683061231; x=1685653231; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject :date:message-id:reply-to; bh=gNqFMrPOOW5jWj7PFAMFZfl7MenLYpZOK/1APyGD8BA=; b=dwzi4EyxUOgBCKeLLJOaFEPfYJF8trFaGW0vZrajPoCYH/6zBQABi/Zn8VGhr6oriz owpwQa0p1mMk5UpNwP4Nb/MUaWYmfIR+PLNtnBLB4ZD/0dQWcMal9XDFX/wdbd4mehI2 YsFQ0C03ltqvXR/+8YlFC8p8KjWqITDTQCzUo7diGxHBLTPaah9tHDLfNaorxn6dqfD3 TDcPMmaSW+C5riTeIBzca2wlUWoBl/YJzse/cNHI3yCTEUSHkbnI0fMaa7LEJ5ksgOcr ktB98TdCheLcCdNeAHqRYxz+beXBbRzfeslq03HQ0Yry/2A33x6ifJXvDrWZrsnpXQ96 NVhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683061231; x=1685653231; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gNqFMrPOOW5jWj7PFAMFZfl7MenLYpZOK/1APyGD8BA=; b=hhjbxjBLzKAs2TqPsXS+mYv9sMYYmGQocmd5NQ3OFxE42iTZ/1nmZiobXxKAG9NB19 d6xvSsEGzZM6pKBtzYP8nWRgsUDrWtPTmMilzmJyaZsWO5REcXJ5a8uZDoCGu2M4j8tz Ajrm5AOm4/xfKWWRsIMTFFygDHcFBSM+RR5jPlDo/hH96avmHN2AZseyNXvjtmD75Wav C6D5itEQ/vM8x3LgNwtS6JUq+r0+UZPwUExFiVBon/OAleYkssVCkdY53rLK4dr1L5jN WfnZpnLxbGZzKDTnF/freIqGHW+XgeEk/OEki2WZ09dCzkyIA+20Wdix4G0tFNBQC5Q2 /nvw== X-Gm-Message-State: AC+VfDyoG2U+xpZ3AicllvUNG9PNSbV9+1evIU4l6KvcuREw3mdUQlSf pn+DRbH9nDpDutHZZDEFVtg= X-Google-Smtp-Source: ACHHUZ6w2HzVwZwYZFHchk54PQbeyMR2lbcuwtlsCa8UY7NQhYfhks/rqFz/K2yhVw2HaQvkwtGX/A== X-Received: by 2002:a05:6512:505:b0:4ef:d4ee:1a6a with SMTP id o5-20020a056512050500b004efd4ee1a6amr282692lfb.44.1683061230622; Tue, 02 May 2023 14:00:30 -0700 (PDT) Original-Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id w3-20020ac254a3000000b004f0c9120a41sm1627557lfk.214.2023.05.02.14.00.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 May 2023 14:00:30 -0700 (PDT) In-Reply-To: <874jou7lsf.fsf@localhost> X-Mailer: Apple Mail (2.3654.120.0.1.15) 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:260958 Archived-At: 2 maj 2023 kl. 18.14 skrev Ihor Radchenko : > | Cache size | Hit | Miss | % miss from total | = ~org-element-parse-buffer~ time | > = |--------------+---------+---------+-------------------+------------------= ---------------| > | 20 (default) | 3219470 | 1491165 | 31.66 | 21.035765s = (1.091127s in 2 GCs) | > | 40 | 4418377 | 293805 | 6.24 | 18.294018s = (1.123854s in 2 GCs) | > | 42 | 4550483 | 161820 | 3.43 | 17.946184s = (1.073528s in 2 GCs) | > | 45 | 4636222 | 76582 | 1.62 | 18.410150s = (1.078844s in 2 GCs) | Good, this quite solidly puts the working set size at 40-odd elements. > The Org parser is basically a giant `cond' of a number of regexp > matches. See `org-element--current-element'. A common way to handle this is to build a big regexp to match many cases = at the same time, essentially transforming (cond ((looking-at RE1) ...) ((looking-at RE2) ...) ...) to (looking-at (rx (or (group RE1) (group RE2) ...))) (cond ((match-beginning 1) ...) ((match-beginning 2) ...) ...) This reduces the number of regexps used and is also typically faster. (Essentially this is what `syntax-propertize-rules` does but in a more = specialised context.) Using tree-sitter for this could very well be even faster but it's not = guaranteed to be available. Otherwise it's very much a matter of optimisation of everything, = including regexps. Minimise backtracking. If you want to match five or more dashes, use "------*" instead of = "-\\{5,\\}". And so on. It's also obviously a good idea not to generate regexps dynamically each = time if you can help it, and minimise consing in general. >> Introducing regexp objects that could store compiled regexps and be >> used instead of strings would be quite some work but probably >> worthwhile. >=20 > What exactly needs to be done? Assuming that regexp objects are not > going to be readable, for simplicity. A proper design, for starters. For example, we probably want them to be = usable in customised variables which calls for them to be readable. > If this is something to be used in practice, it will be more = convenient > to provide a macro like (with-regexp-cache-size N ). Maybe, we'll see if it's something we need to add.