Subject: bug#70796: 30.0.50; bug-reference-mode leading to constant GCing

From: Gerd Möllmann <[email-masked]>
Date: Sat, 25 May 2024 06:34:03 +0200

Tassilo Horn <[email-masked]> writes:

> But anyhow, I don't see how bug-reference-fontify could be so costly
> GC-wise...

It is not by itself, AFAICT. Org fontification allocates which ich not a
problem normally, but with bug-reference active, it is triggered over
and over again.

Interesting observation:

I just built master without native compilation because that's faster.
With .elcs only, I don't seem to get the constant GCs with
9ebe6aa5f1092241a98e0a16db918e3dc1062f1c which is before your fix.
With native compilation I do.

Just double-checked that this is indeed the case. Now it gets
interesting :-/. This is on macOS 14.5, arm64, libgccjit 14.1.

> FWIW, I think goto-address-mode (buttonizing URLs and email addresses)
> will probably have the same effect, at least the code looks pretty
> similar.  Can you confirm?

Yes, goto-address-mode has the same effect.
>
> I'll have a look at you sample file tomorrow.  How do you make GCs
> "visible" so that I can see when excessive GCing starts/stops?

You can use the attached patch to log GC messages in *Messages* which
makes it easier to see. Then load the Org file, expand all nodes (S-TAB
as needed), move a bit around, and see it happening. And set
garbage-collection-messages to t of course.

diff --git a/src/alloc.c b/src/alloc.c
index 28e32554472..7911078ba59 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6584,7 +6584,7 @@ garbage_collect (void)
 #endif /* MAX_SAVE_STACK > 0 */
 
   if (garbage_collection_messages)
-    message1_nolog ("Garbage collecting...");
+    message1 ("Garbage collecting...");
 
   block_input ();
 
@@ -6689,7 +6689,7 @@ garbage_collect (void)
       if (message_p || minibuf_level > 0)
 	restore_message ();
       else
-	message1_nolog ("Garbage collecting...done");
+	message1 ("Garbage collecting...done");
     }
 
   unbind_to (count, Qnil);