Subject: Re: bug#25706: 26.0.50; Slow C file fontification

From: Mattias Engdegård <[email-masked]>
Date: Tue, 1 Dec 2020 13:03:21 +0100

1 dec. 2020 kl. 10.21 skrev Alan Mackenzie <[email-masked]>:

> (i) Take the first 10% of the original 4MB file, and save it in a
>  different file.
> (ii) Fontify that file from top to bottom: according to EPL, 292s
> (iii) Insert 9 new lines "{}" every 10% of that new file.
> (iv) Fontify the amended file top to bottom: new time 98s.
> 
> That's a factor of 3 different.

Thank you, quite remarkable and a very useful piece of information!
Please let me curb some unwarranted optimism that I'm guilty of engendering:

We have been measuring slightly different things. Being lazy, I timed the fontification in one go:

 (font-lock-ensure (point-min) (point-max))

which took about 65 s originally and went down to about 24 s by fixing the regexps as previously mentioned. Much better but still not wonderful.

You have measured interactive scrolling which is more realistic, but fontifying the buffer piecemeal it exercises slightly different code paths. Fixing those regexps helps but not as much, and clearly more work is needed.

(By the way, could you direct me to your benchmark code? I don't think I have it.)

Still, improving regexps is clearly beneficial. Reducing allocation can be effective as well; a fair bit of the profile is in the GC.