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

From: Andrea Corallo <[email-masked]>
Date: Mon, 17 Jun 2024 06:10:51 -0400

Gerd Möllmann <[email-masked]> writes:

> Andrea Corallo <[email-masked]> writes:
>
>> Gerd Möllmann <[email-masked]> writes:
>>
>>> Andrea Corallo <[email-masked]> writes:
>>>
>>>> Tassilo Horn <[email-masked]> writes:
>>>>
>>>>> Andrea Corallo <[email-masked]> writes:
>>>>>
>>>>>> Okay, so this is what I tried:
>>>>>>
>>>>>> I bootstrapped two Emacs from current master (7be66d8223e) one
>>>>>> --with-native-compilation=yes the other --with-native-compilation=no
>>>>>> and boths with Gerd patch applied.
>>>>>>
>>>>>> Also I checkout current scratch/igc (2343d55dff4) to get igc.org.
>>>>>>
>>>>>> I then tried to run with boths native/non-native emacsen with:
>>>>>>
>>>>>> .../src/emacs -eval '(setq garbage-collection-messages t)' -Q
>>>>>> ~/emacs4/admin/igc.org
>>>>>>
>>>>>> Once started looking in *Messages* I see 7 GC cycles in the the
>>>>>> non-native build and 5 in the native one, also I can scroll without
>>>>>> issues or other GC cycles.
>>>>>>
>>>>>> Note that only during the first start the native copiled Emacs did a
>>>>>> number of GC cycles more to jit some code but I guess that's expected.
>>>>>>
>>>>>> Am I trying to repruduce this correctly?
>>>>>
>>>>> Yes.  And you also need to put some function in addition to
>>>>> font-lock-fontify-region in jit-lock-functions, either by enabling
>>>>> bug-reference-mode, goto-address-mode, or simply defining
>>>>>
>>>>>   (defun i-do-nothing (start end) nil)
>>>>>
>>>>> and then M-: (jit-lock-register #'i-do-nothing) RET in the igc.org
>>>>> buffer.
>>>>>
>>>>> Bye,
>>>>>   Tassilo
>>>>
>>>> Okay I tried both your suggestion both Gerd's one on the native compiled
>>>> instance with no effect on the number of GC cycles (I'm on GNU/Linux X86-64).
>>>>
>>>> The best I can do is to try later this afternoon on GNU/Linux AArch64
>>>> and see if something changes.
>>>
>>> Thanks. I'm still suspecting either macOS or libgccjit 14 on arm64, BTW,
>>> or a combination. But I guess I already mentioned that :-).
>>
>> Right I repeated the test on AArch64 using.
>>
>> This is the content of my *Messages* after opening igc.org, defining and
>> registering 'i-do-nothing', and scrolling a bit up and down.
>>
>> =====
>> For information about GNU Emacs and the GNU system, type C-h C-a.
>> Garbage collecting... [25 times]
>> i-do-nothing
>> (jit-lock-function)
>> Garbage collecting...done
>> ===
>>
>> We see some more GC cycles compared to X86_64 at the beginning but I
>> guess that's not the focus here because after 'i-do-nothing' is
>> registered I see only a GC cycle and nothing more (even if I scroll).
>>
>> So to me this all looks good.
>>
>> PS On this machine I'm on libgccjit 13.2.1.
>
> Thanks. I'm currently waiting for a new GCC/libgccjit release which I
> think should happen relatively soon. I'll report back when that happens.
> Much more I cannot do either ATM, I'm afraid.

Maybe you could try my same libgccjit version, this would confirm if
it's a libgccjit version specific bug or it's OS specific.

In case you can build any libgccjit easily from the gcc repo following
[1].

Another approach would be to add the ";; no-native-compile: t" cookie by
bisection to our .el files to discover if a specific compilation unit
being native compiled is causing the issue you observe.

Thanks

  Andrea

[1] <https://gcc.gnu.org/onlinedocs/jit/internals/index.html#working-on-the-jit-library>