From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#9008: 23.2; Sluggishness when editing large latex files containing CJK text using preview-latex, due to slow buf_bytepos_to_charpos Date: Sun, 22 Jun 2014 19:44:47 +0300 Message-ID: <83zjh4sxkw.fsf@gnu.org> References: <1309957253.1342.35.camel@wangqingchuan> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1403455589 1698 80.91.229.3 (22 Jun 2014 16:46:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 22 Jun 2014 16:46:29 +0000 (UTC) Cc: 9008@debbugs.gnu.org To: r6144 Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 22 18:46:22 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1WykuL-0001cC-O8 for geb-bug-gnu-emacs@m.gmane.org; Sun, 22 Jun 2014 18:46:21 +0200 Original-Received: from localhost ([::1]:49659 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WykuL-00088f-CQ for geb-bug-gnu-emacs@m.gmane.org; Sun, 22 Jun 2014 12:46:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WykuA-00087b-Rr for bug-gnu-emacs@gnu.org; Sun, 22 Jun 2014 12:46:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wyku3-0008UP-C8 for bug-gnu-emacs@gnu.org; Sun, 22 Jun 2014 12:46:10 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37876) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wyku3-0008UK-9G for bug-gnu-emacs@gnu.org; Sun, 22 Jun 2014 12:46:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Wyku2-00068T-Ld for bug-gnu-emacs@gnu.org; Sun, 22 Jun 2014 12:46:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 22 Jun 2014 16:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 9008 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 9008-submit@debbugs.gnu.org id=B9008.140345550819705 (code B ref 9008); Sun, 22 Jun 2014 16:46:02 +0000 Original-Received: (at 9008) by debbugs.gnu.org; 22 Jun 2014 16:45:08 +0000 Original-Received: from localhost ([127.0.0.1]:57259 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wykt8-00056I-Hw for submit@debbugs.gnu.org; Sun, 22 Jun 2014 12:45:07 -0400 Original-Received: from mtaout22.012.net.il ([80.179.55.172]:54195) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wykt3-00051s-5V for 9008@debbugs.gnu.org; Sun, 22 Jun 2014 12:45:03 -0400 Original-Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0N7K00900WWJ2Q00@a-mtaout22.012.net.il> for 9008@debbugs.gnu.org; Sun, 22 Jun 2014 19:44:54 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0N7K008DYX6TQP60@a-mtaout22.012.net.il>; Sun, 22 Jun 2014 19:44:54 +0300 (IDT) In-reply-to: <1309957253.1342.35.camel@wangqingchuan> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:90669 Archived-At: > From: r6144 > Date: Wed, 06 Jul 2011 21:00:53 +0800 > > I'm using auctex to edit a large latex file (about 400kB in size) > containing Chinese text as well as about 6000 equations previewed with > preview-latex. Emacs feels a bit sluggish in this mode: individual > cursor movements are not delayed much, but when holding down the right > arrow key, the cursor does not keep moving but only shows up in the new > position after I release the key, while fill-paragraph can take more > than a second. The CPU usage is high during these operations, even > though I have a modern Core 2 Quad CPU. Do you still see this problem with the current Emacs? > According to oprofile, the top consumer of CPU time is > buf_bytepos_to_charpos() within the loop over all the markers. Indeed, > it seems that each preview image (which is an Emacs overlay) has two > markers at respectively its beginning and its end, so the total number > of markers in that buffer, according to > > (with-current-buffer MY-BUFFER > (loop for i from (point-min) to (point-max) count > (buffer-has-markers-at i))) > > is 12856. As buf_bytepos_to_charpos() seems to be called via the > BYTE_TO_CHAR() macro from many places, the sluggishness is well > expected. > > Although having such a large number of markers slows down other > operations as well, they seem necessary when so many preview images are > present. In any case, buf_bytepos_to_charpos() seems to be the most > important one, as operations on another English latex file with a > similar number of preview images is far less sluggish > (buf_bytepos_to_charpos() returns early when there are no multibyte > characters). > > I guess the markers should be organized in something other than a linked > list. Maybe a balanced binary tree ordered by position, with each node > storing the bytepos and charpos offsets compared to its parent? In this > way lookups as well as insertions/deletions should be fast enough. If the problem still exists, I'm not sure what we can do with it. preview-latex is not part of Emacs, and none of its maintainers commented on this report. If indeed buf_bytepos_to_charpos is the hotspot (and it's hard to say, given that oprofile's report was not posted), then I see nothing surprising in that fact, since this function is heavily used when accessing a buffer with lots of non-ASCII characters. If preview-latex is not scalable enough in such buffers, then I suggest to take this issue up with AUCTeX developers first. If they analyze the issue and conclude that there's something wrong with related Emacs primitives, let them come back with more information. At this point I can only say that buf_bytepos_to_charpos is as optimized as we could reasonably make it. In general, any application that uses many overlays will scale badly in the current Emacs. But that doesn't mean we need a separate bug report about each such application. Thanks.