Subject: bug#62780: 30.0.50; Redisplay gets slow when using Org tables + show-trailing-whitespace

From: Eli Zaretskii <[email-masked]>
Date: Fri, 14 Apr 2023 15:23:55 +0300

> Cc: [email-masked]
> Date: Fri, 14 Apr 2023 15:06:17 +0300
> From: Eli Zaretskii <[email-masked]>
> 
> > From: Ihor Radchenko <[email-masked]>
> > Cc: [email-masked]
> > Date: Fri, 14 Apr 2023 11:36:09 +0000
> > 
> > Looking int the code, I can see that handle_display_prop does not call
> > Fnext_single_property_change at all and face_at_pos limits the forward
> > lookup by TEXT_PROP_DISTANCE_LIMIT. In contrast, compute_stop_pos calls
> > composition_compute_stop_pos without making use of
> > TEXT_PROP_DISTANCE_LIMIT (AFAIU) and looks all the way to point-max. (Do
> > I understand correctly that it implies O(N_intervals^2)??)

Btw, it is not true that we are looking all the way to point-max in
this case: you will see in composition_compute_stop_pos that it limits
the search to the next 500 buffer positions:

  void
  composition_compute_stop_pos (struct composition_it *cmp_it, ptrdiff_t charpos,
				ptrdiff_t bytepos, ptrdiff_t endpos,
				Lisp_Object string)
  {
    ptrdiff_t start, end;
    int c;
    Lisp_Object prop, val;
    /* This is from forward_to_next_line_start in xdisp.c.  */
    const int MAX_NEWLINE_DISTANCE = 500;

    if (charpos < endpos)
      {
	if (endpos > charpos + MAX_NEWLINE_DISTANCE)
	  endpos = charpos + MAX_NEWLINE_DISTANCE;
      }
  [...]
    if (charpos < endpos
	&& find_composition (charpos, endpos, &start, &end, &prop, string)
	&& start >= charpos
	&& composition_valid_p (start, end, prop))