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

From: Eli Zaretskii <[email-masked]>
Date: Mon, 01 Aug 2022 14:58:18 +0300

> From: Stefan Monnier <[email-masked]>
> Cc: Eli Zaretskii <[email-masked]>,  [email-masked]
> Date: Sun, 31 Jul 2022 18:45:16 -0400
> 
> Your current code makes it impossible for a major mode to make Emacs
> slow by widening in a too-long-line.  I'd prefer if we made it easy
> (i.e. the default) for Emacs to work well in that case, without making
> it impossible for the major mode to mess things up.
> 
> E.g. use narrowing (and arrange for the known widening culprit to be
> disabled) so that the default behavior is sane, but sllow an ELisp
> package from re-widening (possibly using a specific call to do that) if
> it thinks it's a good idea (even if it may turn out not to be so).

The problem is that too many popular major modes, notably including
those whose files tend to like having very long lines, are slow in
their fontifications.  In fact, I'd challenge you to find a major mode
that doesn't present such a degradation in behavior with long lines
(you should be able to measure it by comparing performance and
responsiveness in a buffer with and without font-lock).

Given this situation, it sounds reasonable to start by restricting
font-lock.

As I wrote elsewhere, I'm okay with extending 'widen' so that it could
"unlock" the locked narrowing, which could then be used in major modes
that convince us their performance is adequate (or clearly announce in
their docs that they don't care about files with long lines ;-).