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:06:17 +0300

> From: Ihor Radchenko <[email-masked]>
> Cc: [email-masked]
> Date: Fri, 14 Apr 2023 11:36:09 +0000
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> >> I cannot reproduce.
> >> The typing has no noticeable delays.
> >
> > Your build is optimized, yes?  Try building without optimizations, you
> > will see quite significant delays just by creating the table.
> 
> Sure, but there is no obvious culprit then:

The culprit is the humongous number of calls to handle_stop, I think.

> 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)??)
> 
> > In any case, if you think disabling static composition can be a
> > reasonable option for Org Table users (do they use
> > prettify-symbols-mode, for example, in the same buffer where they have
> > Org tables?), that should be easy.
> 
> I'd still prefer to find a better way and leave this workaround as the
> last resort.

OK, I have an idea: I think the fact that compute_stop_pos calls
find_composition (via composition_compute_stop_pos) is a mistake,
because the 'composition' text property is found by the previous code
in compute_stop_pos, exactly like we find 'display' and 'fontified'.
So compute_stop_pos has no reason to call find_composition.

But to test this idea, I need enough test cases that use the
'composition' property to make sure the property still works after I
disable that call.  Can you collect a few test cases which use the
'composition' property, with or without Org tables?  I guess
prettify-symbols-mode is one of them, but are there others?  I will
then try to find time to test this idea.