Subject: bug#26051: 25.1; overlays may make emacs very slow

From: Eli Zaretskii <[email-masked]>
Date: Fri, 10 Mar 2017 19:02:59 +0200

> From: [email-masked]
> Date: Sat, 11 Mar 2017 01:25:22 +0900
> 
> 
> Evaluating the form below in the *scratch* buffer,
> it takes a few seconds to show the result.
> 
> (let ((n 65536))
>   (save-excursion (dotimes (i n) (insert (format "%d\n" i))))
>   (dotimes (i n) (make-overlay (point) (progn (forward-line) (point))))
>   (message "Done."))
> 
> If I evaluate the form as below, it takes about 30 seconds.
>   (1) switch to a newly created buffer
>   (2) insert the code into the buffer
>   (3) insert 2 line breaks after the last closing parenthesis
>   (4) type C-x C-e
> 
> If I evaluate the form as below, it takes about 10 minutes.
>   (1) switch to a newly created buffer
>   (2) type M-: and input the code
> 
> In each case, the message "Done." is displayed in a few seconds.
> But it takes a long time to display the buffer contents.

The overlays is not the main problem here, the main problem is that
your buffer is made of digits, which are neutral characters for the
bidirectional display, so it needs to work much harder.  Compare with
this:

  (let ((n 65536))
    (save-excursion (dotimes (i n) (insert (format "a%d\n" i))))
    (dotimes (i n) (make-overlay (point) (progn (forward-line) (point))))
    (message "Done."))

I see no bugs here, just known issues/limitations of the current
display engine.