Subject: Re: bug#1024: Large C++ files load slowly, regardless of font-lock-maximum-size

From: Alan Mackenzie <[email-masked]>
Date: 25 Sep 2008 14:53:03 +0200

Hi, John.

John W <[email-masked]> wrote:
> To reproduce:
> (1) Generate a 3M C++ file.
> (2) Load file.
> (3) Wait for emacs. <-- bug

> I'm using jit-lock, but I tested lazy-lock, and the behavior is the same.

> font-lock-maximum-size is the default.  I.e.
> Its value is 256000

> I used edebug to see what emacs was doing, and it gave me a stack like:

> c-literal-limits()
>  c-neutralize-syntax-in-CPP(1 3527391 3527390)
>  funcall(c-neutralize-syntax-in-CPP 1 3527391 3527390)
>  (if nil c-before-font-lock-function (funcall c-before-font-lock-function (point-min) (point-max) (- ... ...)))
>  (save-excursion (if c-get-state-before-change-function (funcall c-get-state-before-change-function ... ...)) (if nil c-before-font-lock-function (funcall c-before-font-lock-function ... ... ...)))
>  (save-restriction (widen) (save-excursion (if c-get-state-before-change-function ...) (if nil c-before-font-lock-function ...)))
>  c-common-init(c++-mode)
>  c++-mode()
>  set-auto-mode-0(c++-mode nil)
>  set-auto-mode()
>  normal-mode(t)
>  after-find-file(nil t)

Thanks for taking the trouble to generate this stack dump; it identifies
the problem completely.

This bug was caused by a previous bug fix which introduced a complete
scan over the entire buffer when it's loaded.  One function,
`c-neutralize-syntax-in-CPP' had been coded very inefficiently.  It was
recoded for speed on 2008-05-24, committed in
.../emacs/lisp/progmodes/cc-mode.el version 1.58.2.12 (Emacs 22 branch)
and version 1.75 (trunk) at savannah.

To get the fixed version, either:
(i) Upgrade to Emacs 22.3; or
(ii) If you're using the Emacs 23 CVS, update your version.

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).