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

From: Gregory Heytings <[email-masked]>
Date: Sun, 31 Jul 2022 10:50:18 +0000

>
> Emacs is not in the business of preventing people from shooting 
> themselves in the foot.  If we need this narrowing to be enforced 
> because Emacs would otherwise crash, then it's OK, but if not, then we 
> *should* provide a way to undo it.
>

And how do you define "crash"?  Is Emacs becoming unresponsive because an 
operation takes say two minutes to complete and cannot be interrupted a 
"crash"?  Or is a "crash" only a segfault?

>> BTW, my tests show that syntax-ppss can be rather slow, when the file 
>> is large enough (say 1 GB).
>
> No doubt.  But it's no slower with long lines than with short lines.
>

Yes, I wasn't clear enough, I should have written "when the file is large 
enough (say 1 GB), even without long lines".

But you didn't answer my question: is it not possible to design a version 
of syntax-ppss that would approximate, with some heuristics, what 
syntax-ppss does, but on a smaller chunk of the buffer?  With such a 
syntax-ppss-approximate function, we could do something like

(defun syntax-ppss (args)
   (if (narrow-to-region-locked)
       (syntax-ppss-approximage args)
     (syntax-ppss-accurate args)))