Subject: bug#76538: 31.0.50; 31.0.50; 31.0.50; feature/igc: using magit-section-cycle-global (S-TAB) and magit-section-toggle (TAB) in some random ways blocks GNU Emacs.

From: Stefan Monnier <[email-masked]>
Date: Thu, 27 Feb 2025 15:54:18 -0500

> FYI, I tried various tweaks to that loop while debugging and concluded
> that DO_MARKERS loop is not the main bottleneck in this particular bug
> report.

The DO_MARKERS is probably not the main bottleneck nowadays, because the
code explicitly reduces the "estimated benefit" of remaining in the loop
at each iteration and exits once that gets too small.

But that just pushes the problem to the subsequent bytes-scan.

The main problem is simply that we need to make sure some nearby
(cache-)marker is found near the "beginning" of the set of markers we
consider.  Once this set becomes large the ordering between the markers
becomes super-important.  The code on `master` behaves a bit like an
"move to front" policy which works fairly well for the usual locality
properties of buffer navigation, whereas the code on the `igc` branch
has a tendency of putting new entries near the end where they risk not
being found at all, making the cache ineffective.

> I am wondering if anyone else is able to reproduce the problem locally.

I haven't looked at the recipe yet, TBH.
But I strongly suspect that you're seeing something similar to what
happens in the `bytechar-100k-random` benchmark in Helmut Eller's email.

        Stefan