From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Scrolling huge buffers and cc-mode Date: Thu, 20 Dec 2012 22:29:43 +0000 Message-ID: <20121220222943.GA2895@acm.acm> References: <50D03DBD.5000704@yandex.ru> <83txrjp8ry.fsf@gnu.org> <50D158F9.2070303@yandex.ru> <50D16AD7.5060005@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1356042994 3106 80.91.229.3 (20 Dec 2012 22:36:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 20 Dec 2012 22:36:34 +0000 (UTC) Cc: Eli Zaretskii , Stefan Monnier , emacs-devel@gnu.org To: Dmitry Antipov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 20 23:36:48 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TlojL-0003Tk-RK for ged-emacs-devel@m.gmane.org; Thu, 20 Dec 2012 23:36:43 +0100 Original-Received: from localhost ([::1]:41547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tloj8-00084V-70 for ged-emacs-devel@m.gmane.org; Thu, 20 Dec 2012 17:36:30 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:46350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tloj4-00084E-Ns for emacs-devel@gnu.org; Thu, 20 Dec 2012 17:36:29 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tloix-0006ch-Re for emacs-devel@gnu.org; Thu, 20 Dec 2012 17:36:26 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:24814 helo=mail.muc.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tloix-0006bx-Hh for emacs-devel@gnu.org; Thu, 20 Dec 2012 17:36:19 -0500 Original-Received: (qmail 66807 invoked by uid 3782); 20 Dec 2012 22:36:16 -0000 Original-Received: from acm.muc.de (pD95199CB.dip.t-dialin.net [217.81.153.203]) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 20 Dec 2012 23:36:14 +0100 Original-Received: (qmail 4936 invoked by uid 1000); 20 Dec 2012 22:29:43 -0000 Content-Disposition: inline In-Reply-To: <50D16AD7.5060005@yandex.ru> User-Agent: Mutt/1.5.21 (2010-09-15) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 8.x X-Received-From: 193.149.48.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:155706 Archived-At: Hello, Dmitry, On Wed, Dec 19, 2012 at 11:20:55AM +0400, Dmitry Antipov wrote: > It looks like the reason of slow scrolling is how the C++ namespaces are handled. > Basically my test file is: > namespace X { > namespace Y { > /* 13K lines of code */ > } } > /* middle-point */ > namespace X { <============================================== > namespace Y { > /* 13K lines of code */ > } } > When scrolling reaches middle-point, everything hangs, most probably because > we need to scan huge regions (first and second namespace blocks). When I remove > all namespace definitions (with matched '}'), scrolling works much faster. What is happening is that (c-beginning-of-statement-1 ...) is being called repeatedly on the <===== line. o - This moves to the beginning of "namespace X {", o - then calls (scan-sexps (point) -1), o - which has to scan over the 13k lines of code. This is slow. The solution appears to be to give the backward search a search limit. Could you try out the following patch please, and let me know if it works OK: diff -r ce04d3763229 cc-fonts.el --- a/cc-fonts.el Thu Dec 20 20:11:22 2012 +0000 +++ b/cc-fonts.el Thu Dec 20 21:58:50 2012 +0000 @@ -1558,6 +1558,7 @@ ;; prevent a repeat invocation. See elisp/lispref page "Search-based ;; Fontification". (let* ((paren-state (c-parse-state)) + (decl-search-lim (c-determine-limit 1000)) decl-context in-typedef ps-elt) ;; Are we in any nested struct/union/class/etc. braces? (while paren-state @@ -1566,7 +1567,7 @@ (when (and (atom ps-elt) (eq (char-after ps-elt) ?\{)) (goto-char ps-elt) - (setq decl-context (c-beginning-of-decl-1) + (setq decl-context (c-beginning-of-decl-1 decl-search-lim) in-typedef (looking-at c-typedef-key)) (if in-typedef (c-forward-token-2)) (when (and c-opt-block-decls-with-vars-key > Dmitry -- Alan Mackenzie (Nuremberg, Germany).