Subject: bug#79200: 31.0.50; Duplicated elements for '#<marker at' in buffer-undo-list

From: Gerd Möllmann <[email-masked]>
Date: Sun, 10 Aug 2025 16:56:33 +0200

Alan Mackenzie <[email-masked]> writes:

>> I don't believe it creates the markers. But I'm pretty sure that
>> record_change can put a lot of markers to a buffer's undo list. It just
>> considers all markers in a buffer's markers list as relevant for undo.
>> IOW, when we undo, all these markers need their positions changed. It
>> has no way to recognize markers that are only used temporarily. 
>
> In emacs -Q, C-x b foo <RET>.
>
> Now do M-: (length (buffer-marker-list)).  It returns 9.  Repeat.  It
> now returns 14.  Then, successively, 19, 26, 31, 36, ....  OK, between
> the 19 and 26 I had finger trouble.
>
> But it would appear that the command loop, or something close to it, is
> adding five frivolous point markers at each iteration.  This is in my
> "EXPERIMENTAL"ly patched master.  It may be even worse in a vanilla
> master.

Or redisplay like in the mode-line case, as Pip found out. In this
regard, I find the undo mechanism a bit unfortunate, but it has been
that way maybe even since the beginning.

The many "temporary" markers in the undo list should be an removed whit
the next garbage-collect. The function compact_undo_list does that. It
looks for markers that will be deleted because they are no longer
references and removes the undo entries for them. It's a bit like 
a weak hash table containing markers.