Subject: bug#14886: Fwd: bug#14886: Fwd: A significant slowdown calling font-lock-fontify-buffer from a hook

From: Alan Mackenzie <[email-masked]>
Date: Fri, 26 Jul 2013 19:44:28 +0000

Hi, Juanma.

On Thu, Jul 25, 2013 at 08:53:44AM +0200, Juanma Barranquero wrote:
> On Thu, Jul 25, 2013 at 3:24 AM, Stefan Monnier
> <[email-masked]> wrote:

> > I don't see why any of those 3 functions shouldn't be called from
> > a hook, tho.

> Well, it's not that you *must* not call it from a hook, is that if you
> call it when starting Emacs, you can have an unacceptable delay. No
> one on his/her sane mind wants to wait a long time (almost one minute
> in my current setup) to open a file that could be opened in less than
> 1s.

Running

emacs -Q --eval "(progn (add-hook 'prog-mode-hook #'font-lock-fontify-buffer) (setq debug-on-error t))" src/xdisp.c

on Emacs 24.3 (I've added a setting of `debug-on-error', and removed the
final `kill-emacs'), goes quickly.  This suggests that the buffer isn't
fully fontified - instead, merely that the first window of it gets
fontified by jit-lock.

> > Silent errors are bugs.  Please try and find what happens with
> > the error message.

The debug-on-error isn't triggered.  My guess that an error occurred
seems to be wrong.

In the trunk, the entire buffer seems to get fontified, taking ~28s on my
machine.  I think the definition of `font-lock-fontify-buffer' has
changed.  Could this change explain the difference in timings you see?

> I think that's more like Alan's ballpark.

I'm not sure I'm getting very far, here.  IIUC, the problem is that the
initial f-l-fontify-buffer is taking around 72s in some circumstances, as
opposed to 18s (on JB's machine).  I can't reproduce the problem.

>    J

-- 
Alan Mackenzie (Nuremberg, Germany).