Subject: bug#78766: 100-4000x redisplay slowdown with vscroll>0 and make-cursor-line-fully-visible=t

From: Eli Zaretskii <[email-masked]>
Date: Tue, 17 Jun 2025 14:30:58 +0300

> From: JD Smith <[email-masked]>
> Date: Mon, 16 Jun 2025 17:40:46 -0400
> Cc: [email-masked]
> 
> >> Seems to work normally with line-move and tall images.  I will run with it for a while to see if anything else appears.
> > 
> > If that works for you, it's fine by me.  I thought that recentering
> > will effectively disable the effect of vscroll, and so assumed it will
> > be unacceptable for your package.
> 
> Your instincts were good.  The patch was fine in almost all scenarios, but had problems for images taller than the window.  In this situation you have no choice but to keep point on a partially visible top line.  The inherent recentering negatively affects line-move across tall images, especially noticeable for multiple tall lines in a row.
> 
> If we use your top row test as enclosed, this seems to do what we want: avoid the long loop and resulting big slowdown, while permitting the cursor to fall on a partially visible top line.
> 
> Thanks for your efforts.

You are welcome, but now I'm not sure I understand what you are
saying.  Are you saying that the patch you sent, viz.:

> diff --git a/src/xdisp.c b/src/xdisp.c
> index 1106edb6caf..dd726397352 100644
> --- a/src/xdisp.c
> +++ b/src/xdisp.c
> @@ -19218,9 +19218,11 @@ try_scrolling (Lisp_Object window, bool just_this_one_p,
>        if (! cursor_row_fully_visible_p (w, extra_scroll_margin_lines <= 1,
>  					false, false)
>  	  /* It's possible that the cursor is on the first line of the
> -	     buffer, which is partially obscured due to a vscroll
> -	     (Bug#7537).  In that case, avoid looping forever. */
> -	  && extra_scroll_margin_lines < w->desired_matrix->nrows - 1)
> +	     buffer, which is partially obscured due to vscroll
> +	     (Bug#7537).  In that case, just return, since the code
> +	     above is not prepared to deal with that case. */
> +	  && ! (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P
> +		(w, MATRIX_ROW (w->desired_matrix, w->cursor.vpos))))
>  	{
>  	  clear_glyph_matrix (w->desired_matrix);
>  	  ++extra_scroll_margin_lines;

Fixes the problem for you and doesn't have any adverse effects, so I
can install it?