GNU bug report logs - #78665
31.0.50; Very slow saves

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Stefan Monnier <monnier@HIDDEN>; dated Sun, 1 Jun 2025 20:08:03 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

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


Received: (at 78665) by debbugs.gnu.org; 3 Jun 2025 16:48:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jun 03 12:48:21 2025
Received: from localhost ([127.0.0.1]:40814 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uMUoH-0000tW-Hk
	for submit <at> debbugs.gnu.org; Tue, 03 Jun 2025 12:48:21 -0400
Received: from mslow3.mail.gandi.net ([217.70.178.249]:35765)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1uMUoF-0000tC-1u
 for 78665 <at> debbugs.gnu.org; Tue, 03 Jun 2025 12:48:19 -0400
Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net
 [217.70.183.198])
 by mslow3.mail.gandi.net (Postfix) with ESMTP id EA053583B1D
 for <78665 <at> debbugs.gnu.org>; Tue,  3 Jun 2025 15:39:07 +0000 (UTC)
Received: by mail.gandi.net (Postfix) with ESMTPSA id 73C7B43992;
 Tue,  3 Jun 2025 15:39:06 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: bug#78665: 31.0.50; Very slow saves
In-Reply-To: <jwv7c1toklq.fsf-monnier+emacs@HIDDEN>
Organization: LINKOV.NET
References: <jwv5xhfi5uq.fsf@HIDDEN> <86r002ptc2.fsf@HIDDEN>
 <jwva56qs22e.fsf-monnier+emacs@HIDDEN> <867c1up3st.fsf@HIDDEN>
 <jwvwm9uoz9j.fsf-monnier+emacs@HIDDEN>
 <jwv7c1toklq.fsf-monnier+emacs@HIDDEN>
Date: Tue, 03 Jun 2025 18:38:17 +0300
Message-ID: <87frgg7st6.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-GND-State: clean
X-GND-Score: -100
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugdeivdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefujghofhffkfgfgggtsehttdertddtredtnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecuggftrfgrthhtvghrnhepffegteefveelhfeljeefueehieduiedtfffhuddtkeeffffghfevheetgeeukeehnecukfhppeeluddruddvledruddtfedrvdejnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehinhgvthepledurdduvdelrddutdefrddvjedphhgvlhhopehmrghilhdrghgrnhguihdrnhgvthdpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnsggprhgtphhtthhopeegpdhrtghpthhtohepjhhonhgrshessggvrhhnohhulhdrlhhipdhrtghpthhtohepjeekieeiheesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopegvlhhiiiesghhnuhdrohhrghdprhgtphhtthhopehmohhnnhhivghrsehirhhordhumhhonhhtrhgvrghlrdgtrg
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 78665
Cc: Eli Zaretskii <eliz@HIDDEN>, Jonas Bernoulli <jonas@HIDDEN>,
 78665 <at> debbugs.gnu.org
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 (-)

>> AFAICT the problem is that sometimes this heading is already hidden
>> (because of a preceding subtree covering the current one), so we end up
>> going back to the preceding/larger subtree and re-hiding it.  So for
>> a subtree like that of `;;; Code:` covering N smaller subtrees that were
>> previously hidden, we end hiding the `;;; Code:` subtree N times (and
>> each time, this requires looping through all the covered headings),
>> which introduces an O(N^2) complexity.
>
> The patch below seems to fix it (and bug#78673 as well).
> Juri, comments?

I'm testing it.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78665; Package emacs. Full text available.

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


Received: (at 78665) by debbugs.gnu.org; 3 Jun 2025 16:43:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jun 03 12:43:01 2025
Received: from localhost ([127.0.0.1]:40774 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uMUj6-0000Y6-Ot
	for submit <at> debbugs.gnu.org; Tue, 03 Jun 2025 12:43:01 -0400
Received: from mslow3.mail.gandi.net ([217.70.178.249]:43429)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1uMUj3-0000Xn-GZ
 for 78665 <at> debbugs.gnu.org; Tue, 03 Jun 2025 12:42:58 -0400
Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net
 [IPv6:2001:4b98:dc4:8::229])
 by mslow3.mail.gandi.net (Postfix) with ESMTP id 5D13B5806B9
 for <78665 <at> debbugs.gnu.org>; Tue,  3 Jun 2025 15:39:05 +0000 (UTC)
Received: by mail.gandi.net (Postfix) with ESMTPSA id 388C14396B;
 Tue,  3 Jun 2025 15:39:02 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: bug#78665: 31.0.50; Very slow saves
In-Reply-To: <jwvwm9uoz9j.fsf-monnier+emacs@HIDDEN>
Organization: LINKOV.NET
References: <jwv5xhfi5uq.fsf@HIDDEN> <86r002ptc2.fsf@HIDDEN>
 <jwva56qs22e.fsf-monnier+emacs@HIDDEN> <867c1up3st.fsf@HIDDEN>
 <jwvwm9uoz9j.fsf-monnier+emacs@HIDDEN>
Date: Tue, 03 Jun 2025 18:37:01 +0300
Message-ID: <87ldq87uta.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-GND-State: clean
X-GND-Score: -100
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugdeivdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefujghofhffkfgfgggtsehttdertddtredtnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecuggftrfgrthhtvghrnhepffegteefveelhfeljeefueehieduiedtfffhuddtkeeffffghfevheetgeeukeehnecukfhppeeluddruddvledruddtfedrvdejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdefrddvjedphhgvlhhopehmrghilhdrghgrnhguihdrnhgvthdpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnsggprhgtphhtthhopeegpdhrtghpthhtohepjhhonhgrshessggvrhhnohhulhdrlhhipdhrtghpthhtohepjeekieeiheesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopegvlhhiiiesghhnuhdrohhrghdprhgtphhtthhopehmohhnnhhivghrsehirhhordhumhhonhhtrhgvrghlrdgtrg
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 78665
Cc: Eli Zaretskii <eliz@HIDDEN>, Jonas Bernoulli <jonas@HIDDEN>,
 78665 <at> debbugs.gnu.org
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 (-)

> I sent the bug-report because I had finally the backtrace to point the
> finger at something but couldn't investigate further at that point.
> But now that you mention it, maybe the culprit is:
>
>     commit 746a3cb3143194436c4a1a63d26aac890c1a705f
>     Author: Juri Linkov <juri@HIDDEN>
>     Date:   Tue Apr 29 19:55:48 2025 +0300
>
>         Ignore parens in strings for outline headings in emacs-lisp-mode.
>
> [ Poor Juri: while it's his change, I was the one who asked him to install
>   it into `master` since it seemed like an obvious improvement (I mean,
>   it is, but I didn't forsee such impacts on performance).   ]

So Jonas was right?  `syntax-ppss' is too slow
when called too many times?  Maybe it's possible
to reduce the number of calls?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78665; Package emacs. Full text available.

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


Received: (at 78665) by debbugs.gnu.org; 2 Jun 2025 22:18:38 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jun 02 18:18:37 2025
Received: from localhost ([127.0.0.1]:56632 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uMDUL-0001nh-B9
	for submit <at> debbugs.gnu.org; Mon, 02 Jun 2025 18:18:37 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:29374)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1uMDUJ-0001n7-70
 for 78665 <at> debbugs.gnu.org; Mon, 02 Jun 2025 18:18:35 -0400
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id A881F4415BD;
 Mon,  2 Jun 2025 18:18:28 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1748902706;
 bh=ZsIl1H0ShXgtIm8fFFWUjSqijbUzVteNR+oUDPnjHMw=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=hSLqfeCZsOD5eFoXexSfNCT9WeFd7ZtrFWeOOodxI1lHuV5YpkX6GlGC77unQEUQS
 Ejl97ORb9X/efSFlDSdDBDUPsDeeiBGPihbnQCr2UQjO4sV2FuQTI5pqsVhQuMoxDE
 69vywij6IhEsXvxlnyOFFr3KNyotas4rbhqTLqmnDu5T5zib7RnKvh167mce/3xU5K
 2NtOD4HR0/qi+1c3VPj+hlSPRXwGmm6vlzDLOo7n3GWtL2J++NcTtzou9/R0VSYRPl
 +EefiSlUweYo2ColQ/9V7II3JztYbdZBo3bY0rcjR+BwFbonvB3R5H0ZGFAoMSJebS
 cT5+xArG4Xnjw==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id D7AF6441576;
 Mon,  2 Jun 2025 18:18:26 -0400 (EDT)
Received: from alfajor (modemcable005.21-80-70.mc.videotron.ca [70.80.21.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id B1483120406;
 Mon,  2 Jun 2025 18:18:26 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#78665: 31.0.50; Very slow saves
In-Reply-To: <jwvwm9uoz9j.fsf-monnier+emacs@HIDDEN>
Message-ID: <jwv7c1toklq.fsf-monnier+emacs@HIDDEN>
References: <jwv5xhfi5uq.fsf@HIDDEN> <86r002ptc2.fsf@HIDDEN>
 <jwva56qs22e.fsf-monnier+emacs@HIDDEN> <867c1up3st.fsf@HIDDEN>
 <jwvwm9uoz9j.fsf-monnier+emacs@HIDDEN>
Date: Mon, 02 Jun 2025 18:18:13 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.200 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 78665
Cc: Jonas Bernoulli <jonas@HIDDEN>, 78665 <at> debbugs.gnu.org,
 Juri Linkov <juri@HIDDEN>
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 (---)

--=-=-=
Content-Type: text/plain

> AFAICT the problem is that sometimes this heading is already hidden
> (because of a preceding subtree covering the current one), so we end up
> going back to the preceding/larger subtree and re-hiding it.  So for
> a subtree like that of `;;; Code:` covering N smaller subtrees that were
> previously hidden, we end hiding the `;;; Code:` subtree N times (and
> each time, this requires looping through all the covered headings),
> which introduces an O(N^2) complexity.

The patch below seems to fix it (and bug#78673 as well).
Juri, comments?


        Stefan

--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=outline.patch

diff --git a/lisp/outline.el b/lisp/outline.el
index 9d453881b7e..5e8a3360c63 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -685,6 +685,7 @@ outline-next-preface
     (goto-char (match-beginning 0))
     ;; Compensate "\n" from the beginning of regexp
     (when (and outline-search-function (not (bobp))) (forward-char -1)))
+  ;; FIXME: Use `outline--end-of-previous'.
   (when (and (bolp) (or outline-blank-line (eobp)) (not (bobp)))
     (forward-char -1)))
 
@@ -1287,6 +1288,16 @@ outline-flag-subtree
 			  (progn (outline-end-of-subtree) (point))
 			  flag)))
 
+(defun outline--end-of-previous ()
+  "Go back from BOH (or EOB) to end of previous element."
+  (if (eobp)
+      (if (bolp) (forward-char -1))
+    ;; Go to end of line before heading
+    (forward-char -1)
+    (if (and outline-blank-line (bolp))
+        ;; leave blank line before heading
+        (forward-char -1))))
+
 (defun outline-end-of-subtree ()
   "Move to the end of the current subtree."
   (outline-back-to-heading)
@@ -1298,12 +1309,7 @@ outline-end-of-subtree
       (outline-next-heading))
     (if (and (bolp) (not (eolp)))
 	;; We stopped at a nonempty line (the next heading).
-	(progn
-	  ;; Go to end of line before heading
-	  (forward-char -1)
-          (if (and outline-blank-line (bolp))
- 	      ;; leave blank line before heading
- 	      (forward-char -1))))))
+	(outline--end-of-previous))))
 
 (defun outline-show-branches ()
   "Show all subheadings of this heading, but not their bodies."
@@ -1717,8 +1723,8 @@ outline-hide-by-heading-regexp
   (run-hooks 'outline-view-change-hook))
 
 (defun outline--hidden-headings-paths ()
-  "Return a hash with headings of currently hidden outlines.
-Every hash key is a list whose elements compose a complete path
+  "Return a hash-table with headings of currently hidden outlines.
+Every key is a list whose elements compose a complete path
 of headings descending from the top level down to the bottom level.
 This is useful to save the hidden outlines and restore them later
 after reverting the buffer.  Also return the outline where point
@@ -1730,40 +1736,60 @@ outline--hidden-headings-paths
          (current-end (when current-heading-p (pos-eol))))
     (outline-map-region
      (lambda ()
-       (let* ((level (funcall outline-level))
-              (heading (buffer-substring-no-properties (pos-bol) (pos-eol))))
-         (while (and path (>= (cdar path) level))
-           (pop path))
-         (push (cons heading level) path)
-         (when (save-excursion
-                 (outline-end-of-heading)
-                 (seq-some (lambda (o) (eq (overlay-get o 'invisible)
-                                           'outline))
-                           (overlays-at (point))))
-           (setf (gethash (mapcar #'car path) paths) t))
+       (let ((level (funcall outline-level)))
+         (if (outline-invisible-p)
+             ;; Covered by "the" previous heading.
+             (cl-callf (lambda (l) (if (numberp l) (min l level) level))
+                 (gethash (mapcar #'car path) paths))
+           (let ((heading (buffer-substring-no-properties (pos-bol) (pos-eol))))
+             (while (and path (>= (cdar path) level))
+               (pop path))
+             (push (cons heading level) path)
+             (when (save-excursion
+                     (outline-end-of-heading)
+                     (outline-invisible-p))
+               (setf (gethash (mapcar #'car path) paths) t))))
          (when (and current-heading-p (<= current-beg (point) current-end))
            (setq current-path (mapcar #'car path)))))
      (point-min) (point-max))
     (list paths current-path)))
 
 (defun outline--hidden-headings-restore-paths (paths current-path)
-  "Restore hidden outlines from a hash of hidden headings.
+  "Restore hidden outlines from a hash-table of hidden headings.
 This is useful after reverting the buffer to restore the outlines
 hidden by `outline--hidden-headings-paths'.  Also restore point
 on the same outline where point was before reverting the buffer."
-  (let (path current-point outline-view-change-hook)
+  (let ((hidelevel nil) (hidestart nil)
+        path current-point outline-view-change-hook)
     (outline-map-region
      (lambda ()
-       (let* ((level (funcall outline-level))
-              (heading (buffer-substring (pos-bol) (pos-eol))))
-         (while (and path (>= (cdar path) level))
-           (pop path))
-         (push (cons heading level) path)
-         (when (gethash (mapcar #'car path) paths)
-           (outline-hide-subtree))
+       (let ((level (funcall outline-level)))
+         (if (and (numberp hidelevel) (<= hidelevel level))
+             nil
+           (when hidestart
+             (outline-flag-region hidestart
+                                  (save-excursion (outline--end-of-previous)
+                                                  (point))
+                                  t)
+             (setq hidestart nil))
+           (let* ((heading (buffer-substring-no-properties
+                            (pos-bol) (pos-eol))))
+             (while (and path (>= (cdar path) level))
+               (pop path))
+             (push (cons heading level) path)
+             (when (setq hidelevel (gethash (mapcar #'car path) paths))
+               (setq hidestart (save-excursion (outline-end-of-heading)
+                                               (point))))))
          (when (and current-path (equal current-path (mapcar #'car path)))
            (setq current-point (point)))))
      (point-min) (point-max))
+    (when hidestart
+      (outline-flag-region hidestart
+                           (save-excursion
+                             (goto-char (point-max))
+                             (outline--end-of-previous)
+                             (point))
+                           t))
     (when current-point (goto-char current-point))))
 
 (defun outline-revert-buffer-restore-visibility ()

--=-=-=--





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78665; Package emacs. Full text available.

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


Received: (at 78665) by debbugs.gnu.org; 2 Jun 2025 18:49:55 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jun 02 14:49:55 2025
Received: from localhost ([127.0.0.1]:54834 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uMAEM-0002KB-IM
	for submit <at> debbugs.gnu.org; Mon, 02 Jun 2025 14:49:55 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:26149)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1uMAEJ-0002Jl-Io
 for 78665 <at> debbugs.gnu.org; Mon, 02 Jun 2025 14:49:52 -0400
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id D17EA44110A;
 Mon,  2 Jun 2025 14:49:44 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1748890178;
 bh=YhR0Q1PyrRN476XSk7xs+8oxejJEvhVyPrfbGorDCwg=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=T3tIQ2lKDqeomWAXEiyoIyvwtKA215lFHyG013DMUN1+SVXV3BY2p6VHRNndSQWI0
 aD630SGDt8GioG7ZBz34B/oh3SYpm2INy0Fy6HG+Ef0WjorgzEkRus34yurQTnKStX
 eDPMS4vgS1awFywzSTtw0ae1+XoOAsZJcNaTgcfi8wZmTK1wA+yKztM5wQg/VzLz6V
 Q9Kh2avH75DaDBwuLFd+rFJ44NxRtTTxFnRIAZOH7yIj2HkEQwqEG2DSYpw66wOoIS
 uPJajXf0TutL+jU2AU8ojbvl4WPgzEt9IUFfhNVpLbjUMFazWyICAfgmETbETeRtQ9
 9TNZoqRrFSO/g==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id E8B7A4410D1;
 Mon,  2 Jun 2025 14:49:38 -0400 (EDT)
Received: from alfajor (modemcable005.21-80-70.mc.videotron.ca [70.80.21.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id B881F120331;
 Mon,  2 Jun 2025 14:49:38 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#78665: 31.0.50; Very slow saves
In-Reply-To: <867c1up3st.fsf@HIDDEN>
Message-ID: <jwvwm9uoz9j.fsf-monnier+emacs@HIDDEN>
References: <jwv5xhfi5uq.fsf@HIDDEN> <86r002ptc2.fsf@HIDDEN>
 <jwva56qs22e.fsf-monnier+emacs@HIDDEN> <867c1up3st.fsf@HIDDEN>
Date: Mon, 02 Jun 2025 14:49:38 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.202 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 78665
Cc: Jonas Bernoulli <jonas@HIDDEN>, 78665 <at> debbugs.gnu.org,
 Juri Linkov <juri@HIDDEN>
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 (---)

> 10 sec to save that is awfully slow, I agree.
> But I cannot find any change during the recent two months that could
> explain that, maybe I missed something?

I sent the bug-report because I had finally the backtrace to point the
finger at something but couldn't investigate further at that point.
But now that you mention it, maybe the culprit is:

    commit 746a3cb3143194436c4a1a63d26aac890c1a705f
    Author: Juri Linkov <juri@HIDDEN>
    Date:   Tue Apr 29 19:55:48 2025 +0300

        Ignore parens in strings for outline headings in emacs-lisp-mode.

[ Poor Juri: while it's his change, I was the one who asked him to install
  it into `master` since it seemed like an obvious improvement (I mean,
  it is, but I didn't forsee such impacts on performance).   ]

FWIW, I have now a direct way to reproduce the problem:

    src/emacs -Q --batch lisp/transient.el -f outline-minor-mode \
              --eval "(let (f)                                   \
                        (hide-sublevels 1000)                    \
                        (message \"%S\" (benchmark-call (lambda () \
                          (setq f (outline-revert-buffer-restore-visibility))))) \
                        (message \"%S\" (benchmark-call (lambda () \
                          (syntax-ppss-flush-cache (point-min))  \
                          (funcall f)))))"

and I see that it takes ~10s in my usual build (with lots of
assertions and largely unoptimized) but ~1.7s in a more normal build,
so it seems part of the problem is in the specific build options I use
which magnify the performance issue.

In the mean time, I got a more detailed profile:

        7873  83% - normal-top-level
        7873  83%  - command-line
        7873  83%   - command-line-1
        7873  83%    - eval
        7873  83%     - funcall
        7669  81%      - #<byte-code-function F5C>
        7669  81%       - outline--hidden-headings-restore-paths
        7669  81%        - outline-map-region
        7008  74%         - #<byte-code-function F79>
        7008  74%          - outline-hide-subtree
        7008  74%           - outline-flag-subtree
        3710  39%            - outline-back-to-heading
        3686  38%             + elisp-outline-search
          16   0%             + outline-on-heading-p
           4   0%               get-char-property
        3234  34%            - outline-end-of-subtree
        3190  33%             - outline-next-heading
        3182  33%              + elisp-outline-search
          28   0%             + outline-back-to-heading
          12   0%             + lisp-outline-level
          56   0%            + outline-flag-region
           8   0%            + outline-end-of-heading
         661   6%         + outline-next-heading
         204   2%      + outline-revert-buffer-restore-visibility

and I'm surprised by the fact that we spend 39% of the time in
`outline-back-to-heading` but only 0% in `outline-on-heading-p` even
tho, by construction `outline-back-to-heading` is always called from
a BOL looking at the heading of the subtree we want to hide, so it
should just call `outline-on-heading-p` and exit.

AFAICT the problem is that sometimes this heading is already hidden
(because of a preceding subtree covering the current one), so we end up
going back to the preceding/larger subtree and re-hiding it.  So for
a subtree like that of `;;; Code:` covering N smaller subtrees that were
previously hidden, we end hiding the `;;; Code:` subtree N times (and
each time, this requires looping through all the covered headings),
which introduces an O(N^2) complexity.

And indeed a search&replace of `^;;; ` with `;;;; ` in `transient.el`
after `;;; Code:` (so that `;;; Code:` covers the whole file and the
quadratic performance is in full display) brings the time to run the
above test to more than 40s, in the normal build!


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78665; Package emacs. Full text available.

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


Received: (at 78665) by debbugs.gnu.org; 2 Jun 2025 15:21:50 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jun 02 11:21:49 2025
Received: from localhost ([127.0.0.1]:52950 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uM6yz-0002vA-HA
	for submit <at> debbugs.gnu.org; Mon, 02 Jun 2025 11:21:49 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:39712)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1uM6yx-0002uL-JS
 for 78665 <at> debbugs.gnu.org; Mon, 02 Jun 2025 11:21:48 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1uM6yr-0000ZD-Pe; Mon, 02 Jun 2025 11:21:42 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=6p8La5b6T97RCACP7/2v9ug3xnYasBU0ygwvBL7Pkpw=; b=LBs2MWOi50Js
 DXaFUqxGVAUKqgC5+Nh5udUMlBbupb0xBK0YAfEhtdkEqqcg/WN6rdNcQgrsvWAolVuRLSLgw4q6i
 6G+lcgf+Wz3ty62aP1zw7il59foBxjpAuVe9+ENHJET5JbT1hHbpwjLrJcWj22Uxp/pT5RQdChqe1
 /SwLxRlv2RwSkBujrlwhIF/gn+FXZsrdDbMu4+MSJlyKJVMIyo5IiYxRdwDcJ7U0KjqvtcOVP006/
 hFJ9RtP5hbYpq8M80d5Mdoo9hhEqkfr5UTCn4MQj7Hv5/Rkm9NW/cN9GZ5evtm5kZpQAj4qzyW9Bj
 mAVYGnhGKngnKjrMDTfPbA==;
Date: Mon, 02 Jun 2025 18:21:38 +0300
Message-Id: <867c1up3st.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwva56qs22e.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Mon, 02 Jun 2025 09:33:43 -0400)
Subject: Re: bug#78665: 31.0.50; Very slow saves
References: <jwv5xhfi5uq.fsf@HIDDEN> <86r002ptc2.fsf@HIDDEN>
 <jwva56qs22e.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 78665
Cc: 78665 <at> debbugs.gnu.org
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 (---)

> From: Stefan Monnier <monnier@HIDDEN>
> Cc: 78665 <at> debbugs.gnu.org
> Date: Mon, 02 Jun 2025 09:33:43 -0400
> 
> > Two questions:
> >
> >   . was this file under Git, and if not, how did
> >     vc-git-resolve-when-done come into play?
> 
> Yes.
> 
> >   . why does vc-revert-buffer-internal ended up calling
> >     outline--hidden-headings-restore-paths? was outline-minor-mode
> >     active in the buffer?
> 
> Yes, I enable outline-minor-mode in all my ELisp buffers.

OK, so I guess this affects the above combination.

> > IOW, I'd like to better understand the scope of the use cases where
> > saving a buffer is now so much slower.  (How large was the buffer,
> > btw?)
> 
> `transient.el` is about 200kB.

10 sec to save that is awfully slow, I agree.

But I cannot find any change during the recent two months that could
explain that, maybe I missed something?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78665; Package emacs. Full text available.

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


Received: (at 78665) by debbugs.gnu.org; 2 Jun 2025 13:33:54 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jun 02 09:33:54 2025
Received: from localhost ([127.0.0.1]:50446 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uM5IY-0002t4-9o
	for submit <at> debbugs.gnu.org; Mon, 02 Jun 2025 09:33:54 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:40847)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1uM5IV-0002sX-JE
 for 78665 <at> debbugs.gnu.org; Mon, 02 Jun 2025 09:33:52 -0400
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 92FF144138D;
 Mon,  2 Jun 2025 09:33:45 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1748871224;
 bh=xgk0+M47DRyOJU52+GpZaW79rH0MD1c0rpZKBvrW/qU=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=LACCKnSu1B664GiTVc9vV4M0hBFYuCou0ZO2KTXGL15UBkd53FoULa1QuZTv3OvE+
 ISKbuE5AfL0jgKlKbmVJTdoKEjZggQ2V2oqERHYNdYsfCNnxHZODU7iGbq91/xZGxX
 fGOFO2UkcFTLGuQjWEezP5EKIUEOptFndvwrDiX8Az9a0K0UJKjqAQGkYlaiHywWWE
 gVROIfoSSep4HJcNhW4s4agOWClIP154bpzxtam8xJx5066SF588i3XBZacOemG4Iu
 GmGvkncK4hg4JV7Wx4RBVvtnU5fTDyDItIunEFFyALm2MJ7yk15PTrbfq1usP7Lh/H
 5syeSWNXYPR5Q==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id A6E5A4410D1;
 Mon,  2 Jun 2025 09:33:44 -0400 (EDT)
Received: from alfajor (unknown [104.247.225.139])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 74A9F1200DD;
 Mon,  2 Jun 2025 09:33:44 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#78665: 31.0.50; Very slow saves
In-Reply-To: <86r002ptc2.fsf@HIDDEN>
Message-ID: <jwva56qs22e.fsf-monnier+emacs@HIDDEN>
References: <jwv5xhfi5uq.fsf@HIDDEN> <86r002ptc2.fsf@HIDDEN>
Date: Mon, 02 Jun 2025 09:33:43 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.339 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 78665
Cc: 78665 <at> debbugs.gnu.org
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 (---)

> Two questions:
>
>   . was this file under Git, and if not, how did
>     vc-git-resolve-when-done come into play?

Yes.

>   . why does vc-revert-buffer-internal ended up calling
>     outline--hidden-headings-restore-paths? was outline-minor-mode
>     active in the buffer?

Yes, I enable outline-minor-mode in all my ELisp buffers.

>
> IOW, I'd like to better understand the scope of the use cases where
> saving a buffer is now so much slower.  (How large was the buffer,
> btw?)

`transient.el` is about 200kB.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78665; Package emacs. Full text available.

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


Received: (at 78665) by debbugs.gnu.org; 2 Jun 2025 06:10:20 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jun 02 02:10:20 2025
Received: from localhost ([127.0.0.1]:46362 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uLyNI-0006dY-9e
	for submit <at> debbugs.gnu.org; Mon, 02 Jun 2025 02:10:20 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:57540)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1uLyNF-0006dF-Lk
 for 78665 <at> debbugs.gnu.org; Mon, 02 Jun 2025 02:10:18 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1uLyN9-0002ZF-PJ; Mon, 02 Jun 2025 02:10:11 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=KLlXCUn4PcZrcVlCYjYpB1VJDQlqDuuF/Ebi4sviWIQ=; b=qM6M1NKBYWlT
 8PU1vgYrmrQRp967q48+7YDQiGRN266ETZF41lvyaBGP+YrdmVebRnpbF5OmntmgNai5jRpAjLRLs
 xhpkvSJmOxNibMcUMRCCzGzulE6nIk9JW2PN+chXGuU+7X4RVcmr6LzBbIpiqmo3ETRc720/3lrwh
 RJDG62kRZHzlmQA2/78CdA/O8YihhKLM3kI0qkfKbHw6j/gdaXuCiqir0Ot2BkSMpessVORgbfPgk
 hy60cNN2cdR5ZO5DIuuP6TZNsiF7E9AtEoWeXI5Pt9OpoGecfNBAMu5wiyYWsuqnM0rO8j9GBev7q
 Fg9uL3s+kNrumauSHY7yjw==;
Date: Mon, 02 Jun 2025 09:10:05 +0300
Message-Id: <86r002ptc2.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwv5xhfi5uq.fsf@HIDDEN> (bug-gnu-emacs@HIDDEN)
Subject: Re: bug#78665: 31.0.50; Very slow saves
References: <jwv5xhfi5uq.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 78665
Cc: 78665 <at> debbugs.gnu.org
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 (---)

> Cc: monnier@HIDDEN
> Date: Sun, 01 Jun 2025 16:06:53 -0400
> From:  Stefan Monnier via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
> 
> Package: Emacs
> Version: 31.0.50
> 
> 
> The last few weeks I noticed that saving a buffer was sometimes taking
> a very long time (like more than 10s).  I finally managed to catch it
> in the act while running the profiler, and it seems to have something to
> do with `outline--hidden-headings-restore-paths`:
> 
>         9630  75% - command-execute
>         9630  75%  - call-interactively
>         8638  67%   - funcall-interactively
>         8630  67%    - save-buffer
>         8630  67%     - basic-save-buffer
>         8607  67%      - run-hooks
>         8607  67%       - vc-git-resolve-when-done
>         8593  67%        - vc-resynch-buffer
>         8593  67%         - vc-resynch-window
>         8593  67%          - vc-revert-buffer-internal
>         8593  67%           - revert-buffer
>         8353  65%            - mapc
>         8353  65%             - funcall
>         8353  65%              - #<byte-code-function 1FB>
>         8353  65%               - outline--hidden-headings-restore-paths
>         8353  65%                - outline-map-region
>         7748  60%                 - #<byte-code-function 28A>
>         7732  60%                  - outline-hide-subtree
>         7728  60%                   - outline-flag-subtree
>         4268  33%                    + outline-back-to-heading
>         3393  26%                    + outline-end-of-subtree
>           63   0%                    + outline-flag-region
>            4   0%                    + outline-end-of-heading
>            8   0%                  + mapcar
>            4   0%                    gethash
>            4   0%                    pos-bol
>          605   4%                 + outline-next-heading
>          232   1%            + run-hook-wrapped
>            8   0%            + revert-buffer--default
>           14   0%          re-search-forward
>           16   0%      + basic-save-buffer-1
>            4   0%      + vc-before-save
>            3   0%      + vc-after-save
>            8   0%    + execute-extended-command
>          992   7%   + byte-code
>         1855  14% + redisplay_internal (C function)
>         1166   9% + #<byte-code-function 6A0>
>           45   0% + timer-event-handler
>            4   0% + jit-lock--antiblink-post-command
>            4   0% + reveal-post-command
>            0   0%   ...
> 
> This one occurred while saving `transient.el`.
> 
> Maybe we could avoid the whole thing by changing VC to not
> `revert-buffer` (AFAIK this was done to handle the case where CVS/RCS
> would update the "keywords" in the file to reflect its new state, but
> I believe this is basically never done nowadays).
> 
> But in any case `outline--hidden-headings-restore-paths` just takes too
> much time.

Two questions:

  . was this file under Git, and if not, how did
    vc-git-resolve-when-done come into play?
  . why does vc-revert-buffer-internal ended up calling
    outline--hidden-headings-restore-paths? was outline-minor-mode
    active in the buffer?

IOW, I'd like to better understand the scope of the use cases where
saving a buffer is now so much slower.  (How large was the buffer,
btw?)




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78665; Package emacs. Full text available.

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


Received: (at submit) by debbugs.gnu.org; 1 Jun 2025 20:07:42 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jun 01 16:07:41 2025
Received: from localhost ([127.0.0.1]:42269 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uLoy3-0003o5-Rh
	for submit <at> debbugs.gnu.org; Sun, 01 Jun 2025 16:07:41 -0400
Received: from lists.gnu.org ([2001:470:142::17]:43562)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1uLoxz-0003mQ-UX
 for submit <at> debbugs.gnu.org; Sun, 01 Jun 2025 16:07:38 -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 <monnier@HIDDEN>)
 id 1uLoxu-00028L-8V
 for bug-gnu-emacs@HIDDEN; Sun, 01 Jun 2025 16:07:30 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <monnier@HIDDEN>)
 id 1uLoxs-0005UC-Jj
 for bug-gnu-emacs@HIDDEN; Sun, 01 Jun 2025 16:07:30 -0400
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 8E3721002EC
 for <bug-gnu-emacs@HIDDEN>; Sun,  1 Jun 2025 16:07:27 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1748808446;
 bh=+yywbBQtF9G8xX9vx/azsVBmzFUC31ruSK1f/lVehW0=;
 h=From:To:Subject:Date:From;
 b=ItW6mxQ0kxODXqdn2gSHnw4Sp16MNJLGGIpb9MgfjqCpf56zC/UQDO3+6VFE/8khS
 9PkiB2nVwZXhIWWLw3Js913B27Kh3xVp7v6XXbofjbXwnexTgfczabB+YpnZwz/KFZ
 +17/bSLy+UNWLJJ0GbYD29WN3vjQW1t78c7ZaP1b4kqVKoJcOKfWp/0vq/KuLP7mqe
 6bLilMdRVzFwB3ohD6I6Dq1oaCfSqKCbYwtDcgajXLBAffb1tn2O5/artzEXmDPl4p
 SUXrZTRIxk+S5vt+p6VwxnNBzlr9dA8Cs+6IP7FFMQiHGoyTOgmHNvgOc+iBXnjxQd
 j2Y5Pak1uE2lQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 4EA28100034
 for <bug-gnu-emacs@HIDDEN>; Sun,  1 Jun 2025 16:07:26 -0400 (EDT)
Received: from alfajor (unknown [104.247.225.139])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 29226120568
 for <bug-gnu-emacs@HIDDEN>; Sun,  1 Jun 2025 16:07:26 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 31.0.50; Very slow saves
X-Debbugs-Cc: monnier@HIDDEN
Date: Sun, 01 Jun 2025 16:06:53 -0400
Message-ID: <jwv5xhfi5uq.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.337 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
Received-SPF: pass client-ip=132.204.25.50;
 envelope-from=monnier@HIDDEN; helo=mailscanner.iro.umontreal.ca
X-Spam_score_int: -42
X-Spam_score: -4.3
X-Spam_bar: ----
X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3,
 RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: submit
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 (-)

Package: Emacs
Version: 31.0.50


The last few weeks I noticed that saving a buffer was sometimes taking
a very long time (like more than 10s).  I finally managed to catch it
in the act while running the profiler, and it seems to have something to
do with `outline--hidden-headings-restore-paths`:

        9630  75% - command-execute
        9630  75%  - call-interactively
        8638  67%   - funcall-interactively
        8630  67%    - save-buffer
        8630  67%     - basic-save-buffer
        8607  67%      - run-hooks
        8607  67%       - vc-git-resolve-when-done
        8593  67%        - vc-resynch-buffer
        8593  67%         - vc-resynch-window
        8593  67%          - vc-revert-buffer-internal
        8593  67%           - revert-buffer
        8353  65%            - mapc
        8353  65%             - funcall
        8353  65%              - #<byte-code-function 1FB>
        8353  65%               - outline--hidden-headings-restore-paths
        8353  65%                - outline-map-region
        7748  60%                 - #<byte-code-function 28A>
        7732  60%                  - outline-hide-subtree
        7728  60%                   - outline-flag-subtree
        4268  33%                    + outline-back-to-heading
        3393  26%                    + outline-end-of-subtree
          63   0%                    + outline-flag-region
           4   0%                    + outline-end-of-heading
           8   0%                  + mapcar
           4   0%                    gethash
           4   0%                    pos-bol
         605   4%                 + outline-next-heading
         232   1%            + run-hook-wrapped
           8   0%            + revert-buffer--default
          14   0%          re-search-forward
          16   0%      + basic-save-buffer-1
           4   0%      + vc-before-save
           3   0%      + vc-after-save
           8   0%    + execute-extended-command
         992   7%   + byte-code
        1855  14% + redisplay_internal (C function)
        1166   9% + #<byte-code-function 6A0>
          45   0% + timer-event-handler
           4   0% + jit-lock--antiblink-post-command
           4   0% + reveal-post-command
           0   0%   ...

This one occurred while saving `transient.el`.

Maybe we could avoid the whole thing by changing VC to not
`revert-buffer` (AFAIK this was done to handle the case where CVS/RCS
would update the "keywords" in the file to reflect its new state, but
I believe this is basically never done nowadays).

But in any case `outline--hidden-headings-restore-paths` just takes too
much time.


        Stefan





Acknowledgement sent to Stefan Monnier <monnier@HIDDEN>:
New bug report received and forwarded. Copy sent to monnier@HIDDEN, bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to monnier@HIDDEN, bug-gnu-emacs@HIDDEN:
bug#78665; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Tue, 3 Jun 2025 17:00:02 UTC

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