Subject: Re: bug#76504: 31.0.50; Excessive redisplay when display-line-numbers-mode is enabled

From: Davide Masserut <[email-masked]>
Date: Sun, 23 Feb 2025 19:32:36 +0100

Eli Zaretskii <[email-masked]> writes:

> Using line-numbers is a bit more expensive than without them, so on
> machines with weak CPUs it could cross the line between redisplay
> being able to keep up and not being able to keep up with your keyboard
> auto-repeat rate (which will cause choppy redisplay).
>
> What is your keyboard auto-repeat rate on that system?

50 character per second, but I just did the same test with auto-repeat
set at 25 c/s and got the same results (21,480 / 1,875 = 11.456).

However, the difference in behaviour is much smaller, as you probably
expected.

>> The built-in profiler shows that moving the cursor down through my
>> 1200-row init file results in 25,174 redisplays when
>> display-line-numbers-mode is enabled, compared to 2,193 when it is
>> disabled.
>
> Is that a cpu profile or a "memory" profile?  You should use the
> former.

Those are CPU profiles.

> I've used the cpu profiler to scroll through 1700 lines of a large
> file, and I indeed see that with display-line-numbers-mode turned on
> there are more calls to redisplay_internal, but not by factor as large
> as 12 that you see.  I see about 4 times more calls to
> redisplay_internal.

The same test with auto-repeat set to 50 c/s and the balanced power
profile results in a 4.6 factor (10,053 / 2,165).

> Anyway, what's important is the time it takes to scroll through a file
> with and without line numbers.  So please try the command below and
> post the times it reports after scrolling through some large file with
> and without the line numbers:
>
> (defun scroll-up-benchmark ()
>   (interactive)
>   (let ((oldgc gcs-done)
>         (oldtime (float-time)))
>     (condition-case nil (while t (scroll-up) (redisplay))
>       (error (message "GCs: %d Elapsed time: %f seconds"
>                       (- gcs-done oldgc) (- (float-time) oldtime))))))

xdisp.c power-saver
GCs: 492 Elapsed time: 55.600977 seconds
GCs: 493 Elapsed time: 55.490811 seconds

xdisp.c power-saver line numbers
GCs: 488 Elapsed time: 66.925708 seconds
GCs: 495 Elapsed time: 66.195398 seconds

xdisp.c balanced
GCs: 491 Elapsed time: 26.969390 seconds
GCs: 492 Elapsed time: 27.098322 seconds

xdisp.c balanced line numbers
GCs: 494 Elapsed time: 32.596467 seconds
GCs: 494 Elapsed time: 32.593883 seconds