Subject: bug#56682: Fix the long lines font locking related slowdowns

From: Gregory Heytings <[email-masked]>
Date: Sun, 31 Jul 2022 22:54:00 +0000

> Here are my thoughts.

Thanks!

>
> First, I think the setting of narrowed_begv and narrowed_zv should be 
> done in 'reseat', not in init_iterator.  The latter always calls the 
> former when invoked to start iteration of buffer text, but we also call 
> 'reseat' from other places, when we "jump" the iterator to a new place, 
> potentially far from the last.  If nothing else, this should help with 
> truncate-lines, where using window_point is basically right only for the 
> point's line.  And currently, init_iterator computes and sets the 
> narrowing even when we iterate on strings, which is unneeded and 
> incorrect.
>
> Whether always to correct narrowed_begv and narrowed_zv if we are 
> reseating to a position outside the narrowing, is a more complicated 
> question.  The basic problem here is that we don't have an easy way of 
> restoring the previous narrowing (except by unwind_protect), and the 
> display code sometimes calls init_iterator or start_display using the 
> iterator that already has these members set by previous code, a 
> situation which we currently cannot easily detect.  However, when this 
> code runs as part of redisplay, we generally don't expect the original 
> narrowing to be insufficient, except perhaps in the truncate-line case.
>
> So I think we should correct narrowed_begv and narrowed_zv only if 
> either the 'redisplaying_p' flag is reset (meaning the display code is 
> being invoked outside of redisplay) or it->line_wrap == TRUNCATE.
>

I admit I do not really understand your last two paragraphs, but I tried 
to do what you suggested, and it doesn't seem to introduce regressions, so 
I pushed it to the new feature branch.