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

From: Eli Zaretskii <[email-masked]>
Date: Mon, 06 May 2024 17:03:22 +0300

> From: Gerd Möllmann <[email-masked]>
> Cc: [email-masked]
> Date: Mon, 06 May 2024 14:35:42 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > Where's the evidence of "frequent GC" in this profile?
> 
> I didn't say the profile is evidence of frequent GCs.
> 
> > (And "memory profile" has nothing to do with memory usage, contrary to
> > popular belief.)
> >
> >> Disabling bug-reference-mode in the Org buffer makes it stop constantly
> >> GCing.
> >
> > I believe you.  But showing the number of GCs (e.g., using the
> > variable gcs-done) would tell us the story more convincingly.
> > Alternatively, if you can share an Org file where this could be seen,
> > please do.
> 
> So, believe me. Or not, as you please. I said where the Org file is at
> the beginning.

Ah, okay, sorry for missing that.

I tried to scroll through that with Emacs 30 from master, and here's
the CPU profile:

          20  74%   Automatic GC
           4  14% - command-execute
           4  14%  - call-interactively
           2   7%   - funcall-interactively
           2   7%    - scroll-up-command
           2   7%       scroll-up
           2   7%   - byte-code
           2   7%    - read-extended-command
           2   7%     - read-extended-command-1
           2   7%      - completing-read
           2   7%       - completing-read-default
           2   7%        - read-from-minibuffer
           2   7%           redisplay_internal (C function)
           3  11%   redisplay_internal (C function)
           0   0%   ...

I get roughly one GC cycle per full scroll top to bottom.
Interestingly, bug-reference-fontify is not in the profile, perhaps
because it's lower-resolution than on your system with "memory"
profiler.

And here's the profile with bug-reference-mode turned off:

          15  48%   Automatic GC
           8  25%   redisplay_internal (C function)
           8  25% - command-execute
           8  25%  - call-interactively
           4  12%   - funcall-interactively
           3   9%    - scroll-down-command
           3   9%       scroll-down
           1   3%    - scroll-up-command
           1   3%       scroll-up
           4  12%   - byte-code
           3   9%    - read--expression
           3   9%     - read-from-minibuffer
           2   6%        redisplay_internal (C function)
           1   3%    - read-extended-command
           1   3%     - read-extended-command-1
           1   3%      - completing-read
           1   3%       - completing-read-default
           1   3%        - read-from-minibuffer
           1   3%           redisplay_internal (C function)
           0   0%   ...

This does fewer GCs (about 75% of what I see with bug-reference-mode
turned ON), but not by a large factor.

Looking at bug-reference-fontify, I see that it conses a string -- but
it only does that when it finds a match for bug-reference-bug-regexp,
and there are no such matches in igc.org on the branch, AFAICT.

So I'm not sure which part(s) of bug-reference.el make a lot of
garbage, or why.

Ihor, any ideas?