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

From: Ihor Radchenko <[email-masked]>
Date: Tue, 16 Aug 2022 20:25:57 +0800

Eli Zaretskii <[email-masked]> writes:

>> Also, regarding most of the lines being invisible. Unless I miss
>> something, jit-lock actually tries to trigger fontification in the
>> invisible lines when we have something like:
>> -- <window top>
>> * headline
>> <Mbs of invisible text hidden using 'invisible text property>
>> * another headline
>> -- <window bottom>
>
> That 's true, but:
>
>   . jit-lock is called by the display engine, and the display engine
>     skips invisible text
>   . jit-lock calls the fontification functions with a relatively small
>     chunk of buffer text

Apparently large chunks of text were requested in my tests. In any case,
let's not go into this here. Let me re-check these observations again and
file a bug report if I can create a reproducer. This issue is unrelated
to the changes described in the current thread.

> More importantly, when I wrote the above, I wasn't thinking about
> fontifications, I was thinking about the rest of the display code,
> which always skips invisible characters, and skips them using
> relatively fast search for text properties, not the much slower
> iteration through the text one character at a time.

Just in case, please note that Org does not touch 'invisible text
property to hide text. Instead, we set char-property-alias-alist
remapping several other text properties with different non-nil values
into 'invisible. This also means that functions like
`next-single-property-change' may not skip the whole invisible chunk in
one go. Not sure if it is important.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92