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

From: Tassilo Horn <[email-masked]>
Date: Sat, 25 May 2024 09:37:18 +0200

Gerd Möllmann <[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.

I've now checked out the scratch/igc branch and opened admin/igc.org
with the current emacs (master branch) with native compilation + your
gc-messages patch and garbage-collection-messages set to t.  I cannot
reproduce the problem.

I've also added a (message "BRF") as first expression to
bug-reference-fontify.  After scrolling the buffer from top to bottom,
the function won't be called anymore unless I edit some text.  I assume
that in your case, bug-reference-fontify and font-lock-fontify-region
(the latter including the Org fontification) are run over and over again
unless you remove the former...

I have no explanation.  Especially with admin/igc.org,
bug-reference-fontify is essentially a no-op.  There are no bug
references (text matching bug-reference-bug-regexp), so it's just a
regex search with no match and there are no overlays created or moved.
How can a failed regex search somehow trigger another jit-lock cycle
(and only with native compilation on MacOS)?

>> 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.

Alright.  Then you can probably even simplify the issue with

--8<---------------cut here---------------start------------->8---
(defun i-do-nothing (start end) nil)
--8<---------------cut here---------------end--------------->8---

and then M-: (jit-lock-register #'i-do-nothing) RET in some buffer,
right?

Bye,
  Tassilo