From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: r6144 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: Wed, 06 Jul 2011 21:00:53 +0800 Message-ID: <1309957253.1342.35.camel@wangqingchuan> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="GB2312" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1309969184 6074 80.91.229.12 (6 Jul 2011 16:19:44 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 6 Jul 2011 16:19:44 +0000 (UTC) To: 9008@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 06 18:19:38 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QeUp8-0004mZ-9x for geb-bug-gnu-emacs@m.gmane.org; Wed, 06 Jul 2011 18:19:38 +0200 Original-Received: from localhost ([::1]:60721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeUp6-0000r8-KF for geb-bug-gnu-emacs@m.gmane.org; Wed, 06 Jul 2011 12:19:36 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:55484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeUWN-0004CZ-8N for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2011 12:00:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QeUWD-0001nO-SM for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2011 12:00:14 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:60301) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeUWD-0001lt-Ch for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2011 12:00:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QeUWC-0002OI-1N; Wed, 06 Jul 2011 12:00:04 -0400 X-Loop: help-debbugs@gnu.org Resent-From: r6144 Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 06 Jul 2011 16:00:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 9008 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13099679759093 (code B ref -1); Wed, 06 Jul 2011 16:00:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Jul 2011 15:59:35 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QeUVi-0002Mb-3p for submit@debbugs.gnu.org; Wed, 06 Jul 2011 11:59:35 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QeRjF-0005vl-4d for submit@debbugs.gnu.org; Wed, 06 Jul 2011 09:01:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QeRj4-000453-OR for submit@debbugs.gnu.org; Wed, 06 Jul 2011 09:01:15 -0400 Original-Received: from lists.gnu.org ([140.186.70.17]:35163) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeRj4-00044v-Ff for submit@debbugs.gnu.org; Wed, 06 Jul 2011 09:01:10 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:41909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeRiy-0004vB-Fm for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2011 09:01:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QeRiw-00044X-0H for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2011 09:01:04 -0400 Original-Received: from mail-iy0-f169.google.com ([209.85.210.169]:57717) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeRiv-00044S-Kn for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2011 09:01:01 -0400 Original-Received: by iyl8 with SMTP id 8so7629428iyl.0 for ; Wed, 06 Jul 2011 06:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=subject:from:to:content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=12WPMousFzjvr86T+/pZWBzAb3GZZnHzRaVdS94HKdg=; b=Sq5GfQYT8r3+g4Y7hng1kGwNTAgVREvi2c1dohNutUP2Xkv9AFcvDDz1kWjLIXqGmC pcOf/m9xnAvovfa7EUgS/cl31e53SfIzVvs8El5J8YPM2YUP+JFTTGqc/x0Dz8aWoXFJ diVJqoU9W7JwXy21mG+Gb3gwLXW/tNBbHAYP0= Original-Received: by 10.42.168.133 with SMTP id w5mr5509235icy.118.1309957259524; Wed, 06 Jul 2011 06:00:59 -0700 (PDT) Original-Received: from [192.168.1.101] (icnnsp08.sjtu.edu.cn [202.120.36.235]) by mx.google.com with ESMTPS id j7sm8773757icq.2.2011.07.06.06.00.56 (version=SSLv3 cipher=OTHER); Wed, 06 Jul 2011 06:00:58 -0700 (PDT) X-Mailer: Evolution 2.32.2 (2.32.2-1.fc14) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Mailman-Approved-At: Wed, 06 Jul 2011 11:59:33 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Wed, 06 Jul 2011 12:00:04 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-Mailman-Approved-At: Wed, 06 Jul 2011 12:00:52 -0400 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:48083 Archived-At: This bug report will be sent to the Free Software Foundation, not to your local site managers! Please write in English if possible, because the Emacs maintainers usually do not have translators to read other languages for them. Your bug report will be posted to the bug-gnu-emacs@gnu.org mailing list, and to the gnu.emacs.bug news group. Please describe exactly what actions triggered the bug and the precise symptoms of the bug. If you can, give a recipe starting from `emacs -Q': ------------------------------------------------------- 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. 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 Emacs crashed, and you have the Emacs process in the gdb debugger, please include the output from the following gdb commands: `bt full' and `xbacktrace'. For information about debugging Emacs, please read the file /usr/share/emacs/23.2/etc/DEBUG. In GNU Emacs 23.2.1 (x86_64-redhat-linux-gnu, GTK+ Version 2.21.4) of 2010-07-09 on x86-10.phx2.fedoraproject.org Windowing system distributor `Fedora Project', version 11.0.10904000 configured using `configure '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--program-prefix=' '--disable-dependency-tracking' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--with-dbus' '--with-gif' '--with-jpeg' '--with-png' '--with-rsvg' '--with-tiff' '--with-xft' '--with-xpm' '--with-x-toolkit=gtk' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'CFLAGS=-DMAIL_USE_LOCKF -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-optimize-sibling-calls'' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: nil value of $LC_CTYPE: nil value of $LC_MESSAGES: en_US.UTF-8 value of $LC_MONETARY: nil value of $LC_NUMERIC: nil value of $LC_TIME: en_US.UTF-8 value of $LANG: zh_CN.UTF-8 value of $XMODIFIERS: @im=ibus locale-coding-system: utf-8-unix default enable-multibyte-characters: t Major mode: Lisp Interaction Minor modes in effect: eldoc-mode: t diff-auto-refine-mode: t desktop-save-mode: t icomplete-mode: t show-paren-mode: t which-function-mode: t iswitchb-mode: t tooltip-mode: t mouse-wheel-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-encryption-mode: t auto-compression-mode: t column-number-mode: t line-number-mode: t Recent input: M-w C-y C-w C-SPC u i 5 u i 5 C-SPC C-x C-s C-x s C-r d e x t b i t L L C-x C-s C-x s C-s d e x t b i t C-s C-s C-s C-s C-s C-s C-s C-s C-s C-x C-s C-r d e x t b i t C-r C-r C-r C-r C-r C-r C-r M-x r e p o r t SPC e m a c s SPC b u g Recent messages: Wrote /home/r6144/research/degree/thesis/thesis.tex (No files need saving) IBus: is undefined Mark saved where search started Saving file /home/r6144/research/degree/thesis/thesis.tex... Wrote /home/r6144/research/degree/thesis/thesis.tex (No files need saving) Mark saved where search started (No changes need to be saved) Mark saved where search started Load-path shadows: ~/site-lisp/latex hides /usr/share/emacs/site-lisp/auctex/latex /usr/share/cscope/xcscope hides /usr/share/emacs/site-lisp/xcscope /usr/share/emacs/site-lisp/lilypond-init hides /usr/share/emacs/site-lisp/site-start.d/lilypond-init /usr/share/emacs/site-lisp/systemc-mode hides /usr/share/emacs/site-lisp/site-start.d/systemc-mode /usr/share/emacs/site-lisp/site-start.d/maxima-modes hides /usr/share/emacs/site-lisp/maxima/site_start.d/maxima-modes /usr/share/emacs/site-lisp/coq hides /usr/share/emacs/site-lisp/proofgeneral/coq/coq /usr/share/emacs/site-lisp/mmm-noweb hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-noweb /usr/share/emacs/site-lisp/mmm-rpm hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-rpm /usr/share/emacs/site-lisp/mmm-mason hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-mason /usr/share/emacs/site-lisp/mmm-mode hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-mode /usr/share/emacs/site-lisp/mmm-compat hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-compat /usr/share/emacs/site-lisp/mmm-utils hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-utils /usr/share/emacs/site-lisp/mmm-univ hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-univ /usr/share/emacs/site-lisp/mmm-auto hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-auto /usr/share/emacs/site-lisp/mmm-cmds hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-cmds /usr/share/emacs/site-lisp/mmm-vars hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-vars /usr/share/emacs/site-lisp/mmm-sample hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-sample /usr/share/emacs/site-lisp/mmm-cweb hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-cweb /usr/share/emacs/site-lisp/mmm-region hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-region /usr/share/emacs/site-lisp/mmm-class hides /usr/share/emacs/site-lisp/proofgeneral/mmm/mmm-class ~/site-lisp/gud hides /usr/share/emacs/23.2/lisp/progmodes/gud Features: (shadow sort mail-extr message idna sendmail ecomplete rfc822 mml mml-sec password-cache mm-decode mm-bodies mm-encode mailcap mail-parse rfc2231 rfc2047 rfc2045 qp ietf-drums mailabbrev nnheader gnus-util netrc time-date mm-util mail-prsvr gmm-utils mailheader canlock sha1 hex-util hashcash mail-utils emacsbug debug etags reftex-sel cal-julian lunar solar cal-dst cal-move cal-menu calendar cal-loaddefs thingatpt asy-mode cl-specs cl cl-19 reftex-ref reftex-cite help-mode view reftex-parse multi-isearch mule-util texmathp bibtex gud asm-mode fortran cus-edit wid-edit matlab derived tempo rpm-spec-mode compile conf-mode newcomment autoconf autoconf-mode python-21 python comint ring edebug eldoc sh-script executable diff-mode jka-compr make-mode cc-mode cc-fonts cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs latexenc vc-git reftex-vcr reftex-dcr reftex-auc reftex reftex-vars flyspell preview prv-emacs byte-opt tex-buf noutline outline font-latex bytecomp byte-compile latex easy-mmode edmacro kmacro tex-style tex desktop cus-start cus-load uniquify ispell-multi regexp-opt ispell server info-look info easymenu icomplete paren which-func imenu iswitchb preview-latex proof-site proof-autoloads pg-vars ibus advice help-fns advice-preload tex-site auto-loads china-util tooltip ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd font-setting tool-bar dnd fontset image fringe lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar mldrag mouse jit-lock font-lock syntax facemenu font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev loaddefs button minibuffer faces cus-face files text-properties overlay md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote make-network-process dbusbind system-font-setting font-render-setting gtk x-toolkit x multi-tty emacs)