GNU logs - #58950, boring messages


Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#58950: [PATCH] * lisp/subr.el (buffer-match-p): Optimise performance
Resent-From: Philip Kaludercic <philipk@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 01 Nov 2022 19:12:02 +0000
Resent-Message-ID: <handler.58950.B.166732987727196 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 58950
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: 58950 <at> debbugs.gnu.org
X-Debbugs-Original-To: bug-gnu-emacs@HIDDEN
Received: via spool by submit <at> debbugs.gnu.org id=B.166732987727196
          (code B ref -1); Tue, 01 Nov 2022 19:12:02 +0000
Received: (at submit) by debbugs.gnu.org; 1 Nov 2022 19:11:17 +0000
Received: from localhost ([127.0.0.1]:44250 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1opwfI-00074W-V9
	for submit <at> debbugs.gnu.org; Tue, 01 Nov 2022 15:11:17 -0400
Received: from lists.gnu.org ([209.51.188.17]:59336)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <philipk@HIDDEN>) id 1opwfG-00074O-RO
 for submit <at> debbugs.gnu.org; Tue, 01 Nov 2022 15:11:11 -0400
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 <philipk@HIDDEN>)
 id 1opwfG-0005il-Jy
 for bug-gnu-emacs@HIDDEN; Tue, 01 Nov 2022 15:11:10 -0400
Received: from mout02.posteo.de ([185.67.36.66])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <philipk@HIDDEN>)
 id 1opwfD-0000AZ-8s
 for bug-gnu-emacs@HIDDEN; Tue, 01 Nov 2022 15:11:10 -0400
Received: from submission (posteo.de [185.67.36.169]) 
 by mout02.posteo.de (Postfix) with ESMTPS id D189A240103
 for <bug-gnu-emacs@HIDDEN>; Tue,  1 Nov 2022 20:11:04 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1667329864; bh=X3hp3DOimqNA/sHJyFisRQo6gxIdDOOkG9TsQbnfutY=;
 h=From:To:Subject:Autocrypt:Date:From;
 b=QxhFbslYDteLXfV1DEw7k/qzVNyckFS9JRKAA4zRQ1lemsvdzPNsCXBXreaQivC1b
 bHkDrgh4qvTjW1hIsGDV/ia4OmriMP9ytfDtxqvic95668G5PkQoBv2nf7S7gqRCLb
 +oMH3Qv5bOV8Pkb4BBk6oOJaYrnp0qDEQr3ZBoyDXHyyg99pRbTaBaywVTxSheblTJ
 l5fpkBAtWbstp1gynXpnE7KIGPFWtjRFlVnp3uqQmsvxi70y891laqRCfMYq+hSsGs
 vVUODiCfwLRoXaGsxxha2e7zrryWLpZ7YzNEt6YaBJZEsU79c5FNBKLjHfKMDTHkkZ
 gCzDsIyufKVMw==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4N203r1jXYz6tmL
 for <bug-gnu-emacs@HIDDEN>; Tue,  1 Nov 2022 20:11:03 +0100 (CET)
From: Philip Kaludercic <philipk@HIDDEN>
Autocrypt: addr=philipk@HIDDEN; prefer-encrypt=nopreference; keydata=
 mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo
 aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0
 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ
 CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh
 io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF
 AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo
 Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS
 g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB
Date: Tue, 01 Nov 2022 19:11:03 +0000
Message-ID: <875yfyebi0.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@HIDDEN;
 helo=mout02.posteo.de
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.3 (-)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Tags: patch


The below patch is based on a tangent discussion in bug#58839, the below
patch was written in collaboration with Jo=C3=A3o T=C3=A1vora.  It involves=
 an
optimisation to `buffer-match-p' that dramatically speeds the execution
of the function.  This is important for the very least as
`buffer-match-p' is used for displaying buffer.

Running (benchmark-run 1000 (match-buffers "\\*.+\\*")) I previously got
(22.822269875 178 15.524474267999977), and with the patch applied
(0.27100275 2 0.1730835160000197).

There are a few points that can be discussed:

1. Style.  I wrap the defun in a let (or rather letrec) block to avoid
   littering the global namespace.  It isn't necessary, and one could
   argue it makes debugging more difficult.

2. Caching policy.  Caching is critical to this optimisation.  Just
   using byte-compilation would cause the above test to slow down to
   (76.323692627 656 57.088315405).  The question is if the hash map
   will collect too much garbage over time, and if there is a better
   approach that could be taken?

In GNU Emacs 29.0.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version
 3.24.30, cairo version 1.16.0) of 2022-10-31 built on heron
Repository revision: 462a66e79edcc34ecbeef7cc1604765adfdc038e
Repository branch: feature/package+vc
System Description: Guix System

Configured using:
 'configure --with-pgtk --with-imagemagick
 PKG_CONFIG_PATH=3D/gnu/store/ssg343s6ldqdwh30136pnawhbgd0cb6i-profile/lib/=
pkgconfig:/gnu/store/ssg343s6ldqdwh30136pnawhbgd0cb6i-profile/share/pkgconf=
ig'


--=-=-=
Content-Type: text/patch
Content-Disposition: attachment;
 filename=0002-lisp-subr.el-buffer-match-p-Accelerate-using-byte-co.patch

From 0a9ddbcc6958fa7ed94456722a3eee65582a56b2 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@HIDDEN>
Date: Tue, 1 Nov 2022 19:57:49 +0100
Subject: [PATCH] * lisp/subr.el (buffer-match-p): Optimise performance

---
 lisp/subr.el | 75 +++++++++++++++++++++++++++-------------------------
 1 file changed, 39 insertions(+), 36 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index 83e2e75c41..0dd7a814d9 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -7002,8 +7002,38 @@ string-lines
             (setq start (length string)))))
       (nreverse lines))))
 
-(defun buffer-match-p (condition buffer-or-name &optional arg)
-  "Return non-nil if BUFFER-OR-NAME matches CONDITION.
+(letrec ((buffer-sym (make-symbol "buffer"))
+         (arg-sym (make-symbol "arg"))
+         (translate
+          (lambda (condition)
+            "Compile a CONDITION into a predicate function."
+            (pcase-exhaustive condition
+              ((or 't 'nil)
+               condition)
+              ((pred stringp)
+               `(string-match-p ,condition (buffer-name ,buffer-sym)))
+              ((pred functionp)
+               (if (eq 1 (cdr (func-arity condition)))
+                   `(condition ,buffer-sym)
+                 `(condition
+                   ,buffer-sym
+                   ,arg-sym)))
+              (`(major-mode . ,mode)
+               `(eq (buffer-local-value 'major-mode ,buffer-sym)
+                    ',mode))
+              (`(derived-mode . ,mode)
+               `(provided-mode-derived-p
+                 (buffer-local-value 'major-mode ,buffer-sym)
+                 ',mode))
+              (`(not . ,cond)
+               `(not ,(funcall translate cond)))
+              (`(or . ,conds)
+               `(or ,@(mapcar translate conds)))
+              (`(and . ,conds)
+               `(and ,@(mapcar translate conds))))))
+         (cond-cache (make-hash-table :test 'eq)))
+  (defun buffer-match-p (condition buffer-or-name &optional arg)
+    "Return non-nil if BUFFER-OR-NAME matches CONDITION.
 CONDITION is either:
 - the symbol t, to always match,
 - the symbol nil, which never matches,
@@ -7022,40 +7052,13 @@ buffer-match-p
     to be met.
   * `or': the cdr is a list of recursive condition, of which at
     least one has to be met."
-  (letrec
-      ((buffer (get-buffer buffer-or-name))
-       (match
-        (lambda (conditions)
-          (catch 'match
-            (dolist (condition conditions)
-              (when (pcase condition
-                      ('t t)
-                      ((pred stringp)
-                       (string-match-p condition (buffer-name buffer)))
-                      ((pred functionp)
-                       (if (eq 1 (cdr (func-arity condition)))
-                           (funcall condition buffer)
-                         (funcall condition buffer arg)))
-                      (`(major-mode . ,mode)
-                       (eq
-                        (buffer-local-value 'major-mode buffer)
-                        mode))
-                      (`(derived-mode . ,mode)
-                       (provided-mode-derived-p
-                        (buffer-local-value 'major-mode buffer)
-                        mode))
-                      (`(not . ,cond)
-                       (not (funcall match cond)))
-                      (`(or . ,args)
-                       (funcall match args))
-                      (`(and . ,args)
-                       (catch 'fail
-                         (dolist (c args)
-                           (unless (funcall match (list c))
-                             (throw 'fail nil)))
-                         t)))
-                (throw 'match t)))))))
-    (funcall match (list condition))))
+    (funcall (or (gethash condition cond-cache)
+                 (puthash condition
+                          (byte-compile
+                           `(lambda (,buffer-sym ,arg-sym)
+                              ,(funcall translate condition)))
+                          cond-cache))
+             (get-buffer buffer-or-name) arg)))
 
 (defun match-buffers (condition &optional buffers arg)
   "Return a list of buffers that match CONDITION.
-- 
2.38.0


--=-=-=--




Message sent:


Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.505 (Entity 5.505)
Content-Type: text/plain; charset=utf-8
X-Loop: help-debbugs@HIDDEN
From: help-debbugs@HIDDEN (GNU bug Tracking System)
To: Philip Kaludercic <philipk@HIDDEN>
Subject: bug#58950: Acknowledgement ([PATCH] * lisp/subr.el
 (buffer-match-p): Optimise performance)
Message-ID: <handler.58950.B.166732987727196.ack <at> debbugs.gnu.org>
References: <875yfyebi0.fsf@HIDDEN>
X-Gnu-PR-Message: ack 58950
X-Gnu-PR-Package: emacs
X-Gnu-PR-Keywords: patch
Reply-To: 58950 <at> debbugs.gnu.org
Date: Tue, 01 Nov 2022 19:12:02 +0000

Thank you for filing a new bug report with debbugs.gnu.org.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

Your message has been sent to the package maintainer(s):
 bug-gnu-emacs@HIDDEN

If you wish to submit further information on this problem, please
send it to 58950 <at> debbugs.gnu.org.

Please do not send mail to help-debbugs@HIDDEN unless you wish
to report a problem with the Bug-tracking system.

--=20
58950: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D58950
GNU Bug Tracking System
Contact help-debbugs@HIDDEN with problems


Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#58950: [PATCH] * lisp/subr.el (buffer-match-p): Optimise performance
Resent-From: Philip Kaludercic <philipk@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Fri, 04 Nov 2022 23:01:02 +0000
Resent-Message-ID: <handler.58950.B58950.16676028254284 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 58950
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: 58950 <at> debbugs.gnu.org
Received: via spool by 58950-submit <at> debbugs.gnu.org id=B58950.16676028254284
          (code B ref 58950); Fri, 04 Nov 2022 23:01:02 +0000
Received: (at 58950) by debbugs.gnu.org; 4 Nov 2022 23:00:25 +0000
Received: from localhost ([127.0.0.1]:55033 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1or5fl-000170-Gc
	for submit <at> debbugs.gnu.org; Fri, 04 Nov 2022 19:00:25 -0400
Received: from mout01.posteo.de ([185.67.36.65]:33081)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <philipk@HIDDEN>) id 1or5fg-00016g-Jk
 for 58950 <at> debbugs.gnu.org; Fri, 04 Nov 2022 19:00:24 -0400
Received: from submission (posteo.de [185.67.36.169]) 
 by mout01.posteo.de (Postfix) with ESMTPS id 13AD124002B
 for <58950 <at> debbugs.gnu.org>; Sat,  5 Nov 2022 00:00:15 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1667602815; bh=F/sXLNWDxrmVaz9NXg3JdkL54yuregoCr0vvNffAlFY=;
 h=From:To:Subject:Autocrypt:Date:From;
 b=SmlDB2WzSD1V/Kejn/jOgd73FVVnAD6+NTo+ujesH8KwFchutazJ3o1XDG7a4ftlo
 9VgJ9DtuRDpTkCrFgB0tUIbm19HTA7Q0GojdMNfFAiHtx1p6LEKZykvobUb22XQGLI
 A80rPbTGGeNT7s6fbrKWTQjaYF7rpaJ994zt/P2gLO6+LiRE1cWWM3uKdF4DCnsJi8
 5/Np7sEB7JSM8jZn7uUQ3aHkDkNE3V/VliPmgMfk+TkLsTqc9/sCLrv4/JJrDwRHWU
 n1nj1dr1ApekO4PQkHpxQ6KmczMhZLkzAeYdy1YnWY2gBb9u/OIMAQXoP8YRWUZqVW
 pJ/X4N2Ikyufw==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4N3x0t03Pgz6ttj
 for <58950 <at> debbugs.gnu.org>; Sat,  5 Nov 2022 00:00:12 +0100 (CET)
From: Philip Kaludercic <philipk@HIDDEN>
In-Reply-To: <875yfyebi0.fsf@HIDDEN> (Philip Kaludercic's message of "Tue, 
 01 Nov 2022 19:11:03 +0000")
References: <875yfyebi0.fsf@HIDDEN>
Autocrypt: addr=philipk@HIDDEN; keydata=
 mQGNBGLfygUBDADVznbke6w0n9nE42xb+ZggbBy0IYRkkru/K+NA67523YTl2DoR2a5OMW90w7L9
 KDtX2Mp34JN/6jVOSVC07VUbHVu6/exoGKixkiTpGhBPy5tUUJoxQKqLrzVQhN3fIyvg1oyHXKZm
 QGkUeevV0wjj4++xfjmcP235YvDh3TF8HC9t5KxIQIbhWnQm4ZyDkp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eb8A93KRg/8e92CMwKVYtxoADeoksMq10iid4POQl2vw
Date: Fri, 04 Nov 2022 23:00:12 +0000
Message-ID: <878rkqjpfn.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -2.3 (--)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Philip Kaludercic <philipk@HIDDEN> writes:

> Tags: patch
>
>
> The below patch is based on a tangent discussion in bug#58839, the below
> patch was written in collaboration with Jo=C3=A3o T=C3=A1vora.  It involv=
es an
> optimisation to `buffer-match-p' that dramatically speeds the execution
> of the function.  This is important for the very least as
> `buffer-match-p' is used for displaying buffer.
>
> Running (benchmark-run 1000 (match-buffers "\\*.+\\*")) I previously got
> (22.822269875 178 15.524474267999977), and with the patch applied
> (0.27100275 2 0.1730835160000197).
>
> There are a few points that can be discussed:
>
> 1. Style.  I wrap the defun in a let (or rather letrec) block to avoid
>    littering the global namespace.  It isn't necessary, and one could
>    argue it makes debugging more difficult.
>
> 2. Caching policy.  Caching is critical to this optimisation.  Just
>    using byte-compilation would cause the above test to slow down to
>    (76.323692627 656 57.088315405).  The question is if the hash map
>    will collect too much garbage over time, and if there is a better
>    approach that could be taken?
>
> In GNU Emacs 29.0.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version
>  3.24.30, cairo version 1.16.0) of 2022-10-31 built on heron
> Repository revision: 462a66e79edcc34ecbeef7cc1604765adfdc038e
> Repository branch: feature/package+vc
> System Description: Guix System
>
> Configured using:
>  'configure --with-pgtk --with-imagemagick
>  PKG_CONFIG_PATH=3D/gnu/store/ssg343s6ldqdwh30136pnawhbgd0cb6i-profile/li=
b/pkgconfig:/gnu/store/ssg343s6ldqdwh30136pnawhbgd0cb6i-profile/share/pkgco=
nfig'

Ping?




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#58950: [PATCH] * lisp/subr.el (buffer-match-p): Optimise performance
Resent-From: Dmitry Gutov <dgutov@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Mon, 07 Nov 2022 01:05:01 +0000
Resent-Message-ID: <handler.58950.B58950.166778309029383 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 58950
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Philip Kaludercic <philipk@HIDDEN>, 58950 <at> debbugs.gnu.org
Received: via spool by 58950-submit <at> debbugs.gnu.org id=B58950.166778309029383
          (code B ref 58950); Mon, 07 Nov 2022 01:05:01 +0000
Received: (at 58950) by debbugs.gnu.org; 7 Nov 2022 01:04:50 +0000
Received: from localhost ([127.0.0.1]:60944 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1orqZG-0007dr-4v
	for submit <at> debbugs.gnu.org; Sun, 06 Nov 2022 20:04:50 -0500
Received: from mail-wr1-f52.google.com ([209.85.221.52]:34551)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <raaahh@HIDDEN>) id 1orqZA-0007db-Lj
 for 58950 <at> debbugs.gnu.org; Sun, 06 Nov 2022 20:04:48 -0500
Received: by mail-wr1-f52.google.com with SMTP id k8so14142958wrh.1
 for <58950 <at> debbugs.gnu.org>; Sun, 06 Nov 2022 17:04:44 -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:to
 :content-language:subject:user-agent:mime-version:date:message-id
 :sender:from:to:cc:subject:date:message-id:reply-to;
 bh=qzu3dA7mFWJmo4aSwSsRj/PbqS+lVjQKUWXRVGrx3Vo=;
 b=TpFtkLICGd8YMmLdKztdpEFaNU84sxwM7vcv/qblfQ2zVvy//BDedOu2ZrQ7SRz9cA
 Vh7hP3YY2dAkhPuODb9Lql/MSRnCwnONOy6QmQAnC8+HXzZafc0PIb5oPMc52oxoN/Dn
 isBLcfO8xLPBR7agmISTjyJlQcNHewCznSDjqZOSem7HybF4cGjT1QXup0Rb4SSLHRpW
 B8ggVScYzM+dpXvnUhCmXlW7E2YvNJRDqj7wexC+L/bDU1l816H5BTvlH3XWV1bjrwHd
 lUWfvqgmuNFJ7G9zjjZN4jfZbA4rhKzgoSJ9keYoriSAjiig6lwPGutbNbeXtTFnCIwg
 F4Yg==
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: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=qzu3dA7mFWJmo4aSwSsRj/PbqS+lVjQKUWXRVGrx3Vo=;
 b=wL0BzF2Xr7sHDtR9+oTp1uy1SddS2hqb5WsHqpR7FgnrlAG3vP5aWjawijH/UJTlaE
 JVO6tglpmYOkirmKTTR5un44798GHqRD1x+UGVG14lM3reQcgKoMmQJsvm2Xh00cBlwf
 D/w2PxaOzbeZBn+BjtF4Joj2gVTDtHA3FgfRk0RAX1UU2WB2SgPzvxmVFDhvjWyND3g4
 l4ZwIM/u0xGgy+TS6AbmXFau2yhQOvhV9aapfoaJ17WwL1xQmJTZudXszFJGJLdskHLp
 iF0wgmWrpx/J33ga2RCnwDl3RFvGDYM8h9gbsLrRygKWcyQX4d0EGMVxujMBJ6QdqfQa
 WsRw==
X-Gm-Message-State: ACrzQf2hnT02N+EIxXrQZhNOK57RVVX2uMDI+cZF6G09pyZUdc1pU5Qc
 WYMVoH0H46TjMJRjY65Ha74=
X-Google-Smtp-Source: AMsMyM6WsAkgMm+chpw2U428mLPwOIdqpm/GL38uXyNgyvyfQXE61Oy/3BQV9llRCayMrzdpsJ1p+A==
X-Received: by 2002:a5d:4711:0:b0:236:48b6:cb89 with SMTP id
 y17-20020a5d4711000000b0023648b6cb89mr30364336wrq.246.1667783078710; 
 Sun, 06 Nov 2022 17:04:38 -0800 (PST)
Received: from [192.168.0.6] ([46.251.119.176])
 by smtp.googlemail.com with ESMTPSA id
 j7-20020a05600c190700b003b477532e66sm27918395wmq.2.2022.11.06.17.04.37
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Sun, 06 Nov 2022 17:04:38 -0800 (PST)
Message-ID: <c08e7175-aa5c-0c46-7dc0-9be2658cd711@HIDDEN>
Date: Mon, 7 Nov 2022 03:04:35 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
 Thunderbird/102.2.2
Content-Language: en-US
References: <875yfyebi0.fsf@HIDDEN>
From: Dmitry Gutov <dgutov@HIDDEN>
In-Reply-To: <875yfyebi0.fsf@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -1.3 (-)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

On 01.11.2022 21:11, Philip Kaludercic wrote:
> 1. Style.  I wrap the defun in a let (or rather letrec) block to avoid
>     littering the global namespace.  It isn't necessary, and one could
>     argue it makes debugging more difficult.
> 
> 2. Caching policy.  Caching is critical to this optimisation.  Just
>     using byte-compilation would cause the above test to slow down to
>     (76.323692627 656 57.088315405).  The question is if the hash map
>     will collect too much garbage over time, and if there is a better
>     approach that could be taken?

I'd like to let our language-level specialists to take the deeper look.

This approach looks the most straightforward, but there could be others, 
just like "compiling" the form inside defcustom setter (for 
project-kill-buffer-conditions, and every similar option), doing 
precompilation closer to where the rules are used (similar to 
font-lock-compile-keywords), or not doing any of that. All depending on 
how long a typical compilation takes, and how many buffers the user has 
to have, to see any noticeable benefit.

On the last note, I'm curious how many buffers would it take to see a 
50ms improvement in match-buffers' runtime when using the current 
project-kill-buffer-conditions's value, for example.




Message received at control <at> debbugs.gnu.org:


Received: (at control) by debbugs.gnu.org; 12 Nov 2022 20:34:41 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 12 15:34:41 2022
Received: from localhost ([127.0.0.1]:49171 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1otxD7-0004nm-5v
	for submit <at> debbugs.gnu.org; Sat, 12 Nov 2022 15:34:41 -0500
Received: from mail-ot1-f53.google.com ([209.85.210.53]:42553)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <stefankangas@HIDDEN>) id 1otxD5-0004nX-Tj
 for control <at> debbugs.gnu.org; Sat, 12 Nov 2022 15:34:40 -0500
Received: by mail-ot1-f53.google.com with SMTP id
 a13-20020a9d6e8d000000b00668d65fc44fso4620506otr.9
 for <control <at> debbugs.gnu.org>; Sat, 12 Nov 2022 12:34:39 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=to:subject:message-id:date:mime-version:from:from:to:cc:subject
 :date:message-id:reply-to;
 bh=zBRPi+jwqMOrZAE2bj9M8vNMYfc3lwbxcDEwojGtc/E=;
 b=cmkr5rtXYOQ/lKF4H7+sgUC+xPUcf1ZDalLcU5sR85Ko5od7r5rk7PsEROQSf+GvER
 stE+v4+LMDJjRvyNMH5Ab3KTQIQ2BzhgzfKSDOT+WkivaOjte3N6q6hRoMN6kYiX6l3l
 1gJwmdvSnYluKGmHwmwsLl+wxIPpcOufiZ4nUsaxQDPzhKsPEOxnpwfuZeiG12aEk07Q
 ly55JIyx1bKKm/jp4tmrmk60XoEfTDj+TGLxRhyaXg8JDQM58h9EvpzuGk7qAoXvLgs7
 nxbnKXbLu1zdsbhkh6i++sBGiT9YqrRNNPAdDLdg2iIYTf0vIu4yL6vkOV2keXdEDfPO
 Dx5Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=to:subject:message-id:date:mime-version:from:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=zBRPi+jwqMOrZAE2bj9M8vNMYfc3lwbxcDEwojGtc/E=;
 b=5VPixV+TbFxare5DEEfs81LYEY8U6e3VG8oZTGPTxuod9g3n4YoQ8iNsmQD/HghMqK
 mYY+3qZwJqmdS3WMJCXR56yRRoW2fjvYGPWCQRTcwM4ZJ07TbTC53WMCWIa6FEg3JfZs
 h8KUnb4JZT9FEqqg+SVKOR203ApfTonnOmwhWJRSgQUc4EhoVd3fpPPOPb81qg6caRDa
 UHK36+Vsu11lMdJBunuzYa/AcItBsPvDxFuRSdI1AqZWqIN0U2X7j561pudi2KHs/LOh
 JgGgl3vM6ZBfuYAg10FQvprA1pv6WPtpZbofVK30NtyxoMz1TPYXL7r31zpfZRo9eGdV
 QdwA==
X-Gm-Message-State: ANoB5plOfWxpE1/JlEgTO8sQlO+/A8av3Dy55vgZ6fc+mQiT7Hd4Jksz
 AIZfwRihx9T+dzDXYpbR4qpKMuzVYqCAaLzs6N5vbL7Q
X-Google-Smtp-Source: AA0mqf4wJlOtTS7UBFxIKxdTlxkqdkoVYQUyvx2kHxThATjcS6PujOfLP9kthd0Irmxr9D2A78rAqzVReaE0Rj+jifw=
X-Received: by 2002:a9d:4f10:0:b0:66c:5232:b9d1 with SMTP id
 d16-20020a9d4f10000000b0066c5232b9d1mr3721957otl.224.1668285274490; Sat, 12
 Nov 2022 12:34:34 -0800 (PST)
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Sat, 12 Nov 2022 12:34:34 -0800
From: Stefan Kangas <stefankangas@HIDDEN>
X-Hashcash: 1:20:221112:control <at> debbugs.gnu.org::mmpYfKG/GCKTWIrA:nGD
MIME-Version: 1.0
Date: Sat, 12 Nov 2022 12:34:34 -0800
Message-ID: <CADwFkmm240eyLPXuzaKB9evotX_Q0nYk8EwOF9=FcBy0hYSU3w@HIDDEN>
Subject: control message for bug #58950
To: control <at> debbugs.gnu.org
Content-Type: text/plain; charset="UTF-8"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: control
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

severity 58950 wishlist
quit





Last modified: Sat, 12 Nov 2022 20:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.