Subject: bug#71644: 30.0.50; Severe slowdown in larger files with markers beginning in emacs 29+

From: Eli Zaretskii <[email-masked]>
Date: Fri, 21 Jun 2024 09:48:58 +0300

> From: Mitchell <[email-masked]>
> Date: Thu, 20 Jun 2024 20:46:51 -0600
> Cc: [email-masked]
> 
> > If you remove all the non-ASCII characters from the Org file, does the
> > slowdown go away?
> 
> Eli, that solved it! The new test file is at
> https://gist.github.com/kings2u/2ef0e145f2b42d0a13605b0dc9b6e6e2. I replaced every non-ASCII character
> with an "a" so the file still has the same number of total characters, and in my emacs 30.0 50 build (as of
> 2024-05-25), doing Steps 1 to Step 7 gives me abbrev expansions that are as lighting fast as in emacs 28.2!
> 
> So what now? Do you think you can solve what’s going on in the backend so bigger buffers with markers and
> non-ASCII characters don’t exhibit this slowness in the latest emacs? 

The fact that the problem goes away when you remove non-ASCII
characters is a pretty convincing argument in favor of your theory
that markers are involved.  Because Emacs consults the buffer's
markers whenever it needs to convert character positions to byte
positions or vice versa, which is done _a_lot_.

The only significant change I see in markers code that could be
related to converting character to byte positions is this:

  commit 8783700b23e70874c4996908bf02c010ae6f3fe1
  Author:     Stefan Monnier <[email-masked]>
  AuthorDate: Tue Aug 2 10:38:53 2022 -0400
  Commit:     Stefan Monnier <[email-masked]>
  CommitDate: Tue Aug 2 13:06:51 2022 -0400

      * src/xdisp.c (redisplay_window): Use BEG rather than hard coding 1

It changed the comparison operator in two places in marker.c.

Curiously, the log message doesn't even mention the change in
marker.c, which could be a sign that this change was not intended to
be installed.  Stefan, did you intend to install it, and if so, do you
have any comments about this bug report?

I'm a bit confused by the fact that I don't see the slowdown on my
machine, but maybe there are other factors at work here that hide the
regression.