Subject: bug#77942: 31.0.50; replace-region-contents gets stuck

From: Gerd Möllmann <[email-masked]>
Date: Mon, 21 Apr 2025 22:42:16 +0200

Stefan Monnier <[email-masked]> writes:

> Gerd Möllmann [2025-04-21 20:01:43] wrote:
>> Stefan Monnier <[email-masked]> writes:
>>>> This enters an (infinite?) loop
>>>
>>> AFAICT it's not infinite.  At least, it does end for me when the buffer
>>> is smaller (100000) and it does take more time (but still end) with
>>> a buffer of 500000, so I think it would end *eventually*.
>>
>> Just as an observation: I started with 1 run and that seemed reasonably
>> fast, a few seconds, so I made it 100, which had this effect.
>
> For the first round, how fast is it depends on your luck with the random
> number generator since the time depends on the size of the region on
> which you perform the replace.
>
> Try just
>
>     (require 'subr-x)
>     
>     (defun elb-replace-region-contents-entry ()
>       (with-temp-buffer
>         (let ((step (apply #'concat (make-list 2000 "🙂été👶🏿 "))))
>           (dotimes (_ (/ 1000000 (length step)))
>             (insert step)))
>     
>         (replace-region-contents 123 (- (point-max) 123)
>                                  (lambda () "🙂été👶🏿 🙂été👶🏿 "))))
>

Yep, I've read the code now, and the O(ND) diffing was, well, a bit
suprising :-).