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

From: Eli Zaretskii <[email-masked]>
Date: Sun, 23 Feb 2025 18:10:35 +0200

> Date: Sun, 23 Feb 2025 16:27:50 +0100
> From:  Davide Masserut via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> To reproduce:
> - Open a file with many lines
> - Enable display-line-numbers-mode
> - Hold down C-n
> 
> On my T480s (i5-8350U) in power-saving mode, this results in choppy cursor
> movement.

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?

> 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.

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.

Anyway, why is the number of calls to redisplay_internal an issue?
Emacs calls redisplay_internal when it's idle, so the number of calls
does not necessarily say anything of importance.