GNU bug report logs - #5734
23.1.94; (forward-sexp N) at the very end of large latex-mode buffer takes time proportional to N

Previous Next

Package: emacs;

Reported by: joaotavora <at> gmail.com (Joao Tavora)

Date: Wed, 17 Mar 2010 22:11:02 UTC

Severity: normal

Done: Chong Yidong <cyd <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 5734 in the body.
You can then email your comments to 5734 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5734; Package emacs. (Wed, 17 Mar 2010 22:11:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to joaotavora <at> gmail.com (Joao Tavora):
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 17 Mar 2010 22:11:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: joaotavora <at> gmail.com (Joao Tavora)
To: bug-gnu-emacs <at> gnu.org
Subject: 23.1.94;
	(forward-sexp N) at the very end of large latex-mode buffer takes
	time proportional to N
Date: Wed, 17 Mar 2010 23:04:18 +0100
Hi,

This originated in http://code.google.com/p/autopair/issues/detail?id=21: 

start with `emacs -Q'
M-x eval-expression RET (insert (make-string 100000 ?a)) RET 
M-x eval-expression RET (latex-mode)                     RET 
M-x eval-expression RET (forward-sexp 200)               RET 
M-x eval-expression RET (forward-sexp 500)               RET 
M-x eval-expression RET (forward-sexp (point-max))       RET 

In some versions of emacs this does not happen, notably my earlier
Carbon Emacs "GNU Emacs 22.3.1 (i386-apple-darwin9.7.0, Carbon Version
1.6.0) of 2009-07-26 on gs674-seijiz.local" after loading some lisp
libraries (don't know which), like the ones I have bellow (autopair,
yasnippet).

The purpose I use these kind of calls to `forward-sexp' is to check if
the buffer is sexp-balanced, as in autopair.el. Now I think I can work
around this in my lisp code without using this kind of call, but
still...

When point reaches the end of the buffer, scan_lists in
syntax.c can just return right? 

Thanks in advance,
Joao Tavora

In GNU Emacs 23.1.94.5 (x86_64-apple-darwin10.2.0, NS apple-appkit-1038.25)
 of 2010-03-16 on king.local
Windowing system distributor `Apple', version 10.3.1038
configured using `configure  '--with-ns''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: nil
  value of $XMODIFIERS: nil
  locale-coding-system: nil
  default enable-multibyte-characters: t

Major mode: Apropos

Minor modes in effect:
  shell-dirtrack-mode: t
  yas/global-mode: t
  display-time-mode: t
  cua-mode: t
  autopair-mode: t
  autopair-global-mode: t
  global-hl-line-mode: t
  recentf-mode: t
  show-paren-mode: t
  ido-everywhere: t
  global-hs-mode: t
  heretic/mode: 0
  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
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<wheel-down> <double-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <wheel-up> <double-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <triple-wheel-up> <triple-wheel-up> 
<wheel-down> <double-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <wheel-down> <double-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <wheel-up> <double-wheel-up> <triple-wheel-up> 
<triple-wheel-up> <down-mouse-1> <mouse-1> <wheel-down> 
<double-wheel-down> <triple-wheel-down> <triple-wheel-down> 
<triple-wheel-down> <triple-wheel-down> <down-mouse-1> 
<mouse-1> s-x M-< C-n C-n C-n C-n C-n C-n C-n C-n C-n 
C-n C-n C-n C-n M-x e m a c <tab> r e p o <tab> <backspace> 
<backspace> <backspace> <backspace> b u <tab> <tab> 
<tab> <backspace> <backspace> <tab> C-g M-x b C-g M-x 
a p r o p o s RET b u g <tab> <backspace> RET C-x o 
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-s e m a c 
s C-s C-s C-s C-p C-b C-b C-b C-b C-b C-b RET C-n C-n 
C-n C-n C-n C-n C-n C-p C-p C-p C-p C-p C-p C-p C-p 
C-p C-p C-p C-p C-p C-p C-p C-n C-n C-n C-n C-n C-n 
M-x r e p o r t SPC e m a c <tab> RET

Recent messages:
1293422 (#o4736156, #x13bc6e)
nil [2 times]
byte-code: End of buffer [2 times]
byte-code: Beginning of buffer [2 times]
byte-code: End of buffer [7 times]
Mark set
Making completion list...
Quit [2 times]
Mark saved where search started
Type M-x display-buffer RET to restore the other window.

Load-path shadows:
/Applications/Emacs - 23.app/Contents/Resources/lisp/progmodes/flymake hides /Volumes/home/capitaomorte/holy/share/emacs/common/site-lisp/10hacks/flymake
/Applications/Emacs - 23.app/Contents/Resources/lisp/linum hides /Volumes/home/capitaomorte/holy/share/emacs/common/site-lisp/20misc/linum
/Volumes/home/capitaomorte/holy/share/emacs/common/site-lisp/yasnippet/extras/imported/html-mode/.yas-setup hides /Volumes/home/capitaomorte/holy/share/emacs/common/site-lisp/yasnippet/extras/imported/objc-mode/.yas-setup
/Volumes/home/capitaomorte/holy/share/emacs/common/site-lisp/yasnippet/extras/imported/html-mode/.yas-setup hides /Volumes/home/capitaomorte/holy/share/emacs/common/site-lisp/yasnippet/extras/imported/rails-mode/.yas-setup
/Volumes/home/capitaomorte/holy/share/emacs/common/site-lisp/yasnippet/extras/imported/html-mode/.yas-setup hides /Volumes/home/capitaomorte/holy/share/emacs/common/site-lisp/yasnippet/extras/imported/ruby-mode/.yas-setup

Features:
(shadow sort mail-extr gnus-msg emacsbug apropos ispell tex-mode
yasnippet tramp-imap tramp-gw tramp-fish tramp-smb tramp-cache tramp-ftp
tramp-cmds tramp auth-source shell tramp-compat trampver jka-compr
find-func help-mode debug vc-svn ffap multi-isearch cedet dropdown-list
woman man assoc highlight-regexp ruby-mode flymake perl-find-library
cperl-mode sgml-mode nxml-mode nxml-outln nxml-rap nxml-util nxml-glyph
nxml-enc xmltok time imenu cua-base autopair hl-line windmove uniquify
recentf tree-widget paren ido hideshowvis hideshow ediff-merg ediff-diff
ediff-wind ediff-help ediff-util ediff-mult ediff-init ediff vc
vc-dispatcher gnus-cite gnus-art mm-uu mml2015 pgg pgg-parse pgg-def
epg-config mm-view smime dig gnus-sum nnoo gnus-group gnus-undo nnmail
mail-source format-spec gnus-start gnus-spec gnus-int message ecomplete
rfc822 mml mml-sec password-cache mm-decode mm-bodies mm-encode mailcap
mail-parse rfc2231 rfc2047 rfc2045 qp ietf-drums mailabbrev gmm-utils
mailheader canlock sha1 hex-util hashcash gnus-win gnus-range gnus
gnus-ems nnheader gnus-util netrc time-date mail-utils mm-util
mail-prsvr em-cmpl em-term term disp-table ehelp electric em-prompt
esh-var esh-io esh-cmd esh-ext esh-proc esh-arg eldoc esh-groups eshell
esh-module esh-mode esh-util server idle-highlight vc-ediff
dired-details+ dired-details dired-x dired-aux dired view thingatpt
rcompile cc-mode cc-fonts cc-menus cc-cmds cc-styles cc-align cc-engine
cc-vars cc-defs regexp-opt advice help-fns advice-preload ibuffer
package reporter zenburn color-theme edmacro kmacro wid-edit heretic
heretic-project ack derived grep compile comint ring easy-mmode holy cl
cl-19 tooltip ediff-hook vc-hooks lisp-float-type mwheel ns-win easymenu
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 ns multi-tty emacs)





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5734; Package emacs. (Thu, 25 Mar 2010 19:18:02 GMT) Full text and rfc822 format available.

Message #8 received at 5734 <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> stupidchicken.com>
To: joaotavora <at> gmail.com (Joao Tavora)
Cc: 5734 <at> debbugs.gnu.org
Subject: Re: 23.1.94;
	(forward-sexp N) at the very end of large latex-mode buffer takes
	time proportional to N
Date: Thu, 25 Mar 2010 15:17:12 -0400
> start with `emacs -Q'
> M-x eval-expression RET (insert (make-string 100000 ?a)) RET
> M-x eval-expression RET (latex-mode)                     RET
> M-x eval-expression RET (forward-sexp 200)               RET
> M-x eval-expression RET (forward-sexp 500)               RET
> M-x eval-expression RET (forward-sexp (point-max))       RET

> In some versions of emacs this does not happen, notably my earlier
> Carbon Emacs "GNU Emacs 22.3.1 (i386-apple-darwin9.7.0, Carbon Version
> 1.6.0) of 2009-07-26 on gs674-seijiz.local" after loading some lisp
> libraries (don't know which), like the ones I have bellow (autopair,
> yasnippet).

I can reproduce this slowness even on Emacs 22.3.  It arises because
tex-mode wants to be able to signal an error if point is in a containing
expression that ends prematurely, so it does a bit of backtracking.
(This is the `skip-syntax-backward' call in latex-forward-sexp-1).

I'm not sure what the best way to fix this is, though.




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5734; Package emacs. (Thu, 25 Mar 2010 19:55:02 GMT) Full text and rfc822 format available.

Message #11 received at 5734 <at> debbugs.gnu.org (full text, mbox):

From: João Távora <joaotavora <at> gmail.com>
To: 5734 <at> debbugs.gnu.org
Subject: Fwd: 23.1.94;
	(forward-sexp N) at the very end of large latex-mode buffer takes
	time proportional to N
Date: Thu, 25 Mar 2010 20:54:06 +0100
[Message part 1 (text/plain, inline)]
Forgot to cc the bug db.

Begin forwarded message:

> From: João Távora <joaotavora <at> gmail.com>
> Date: March 25, 2010 8:52:47 PM GMT+01:00
> To: Chong Yidong <cyd <at> stupidchicken.com>
> Subject: Re: 23.1.94; (forward-sexp N) at the very end of large latex-mode buffer takes time proportional to N
> 
> What about this? This was the workaround I used in autopair.el. The
> idea behind is that if one `latex-forward-sexp-1' went nowhere, the
> next one probably isn't going to. I may be wrong :-)
> 
> === modified file 'lisp/textmodes/tex-mode.el'
> --- lisp/textmodes/tex-mode.el	2010-02-16 02:42:03 +0000
> +++ lisp/textmodes/tex-mode.el	2010-03-25 19:42:59 +0000
> @@ -1651,9 +1651,12 @@
>   "Like `forward-sexp' but aware of multi-char elements and escaped parens."
>   (interactive "P")
>   (unless arg (setq arg 1))
> -  (let ((pos (point)))
> +  (let ((pos (point))
> +        (prev-pos 0))
>     (condition-case err
> -	(while (/= arg 0)
> +	(while (and (not (eq prev-pos (point)))
> +                    (/= arg 0))
> +          (setq prev-pos (point))
> 	  (setq arg
> 		(if (> arg 0)
> 		    (progn (latex-forward-sexp-1) (1- arg))
> 
> PS: I hadn't realised that `tex-mode' defines a `forward-sexp-function'
> hence my ignorant comment about the problem being in syntax.c's scan_list.
> 
> Bye,
> João
> 
> On Mar 25, 2010, at 8:17 PM, Chong Yidong wrote:
> 
> start with `emacs -Q'
> M-x eval-expression RET (insert (make-string 100000 ?a)) RET
> M-x eval-expression RET (latex-mode)                     RET
> M-x eval-expression RET (forward-sexp 200)               RET
> M-x eval-expression RET (forward-sexp 500)               RET
> M-x eval-expression RET (forward-sexp (point-max))       RET
> 
> In some versions of emacs this does not happen, notably my earlier
> Carbon Emacs "GNU Emacs 22.3.1 (i386-apple-darwin9.7.0, Carbon Version
> 1.6.0) of 2009-07-26 on gs674-seijiz.local" after loading some lisp
> libraries (don't know which), like the ones I have bellow (autopair,
> yasnippet).
> 
> I can reproduce this slowness even on Emacs 22.3.  It arises because
> tex-mode wants to be able to signal an error if point is in a containing
> expression that ends prematurely, so it does a bit of backtracking.
> (This is the `skip-syntax-backward' call in latex-forward-sexp-1).
> 
> I'm not sure what the best way to fix this is, though.
> On Mar 25, 2010, at 8:17 PM, Chong Yidong wrote:
> 
>>> start with `emacs -Q'
>>> M-x eval-expression RET (insert (make-string 100000 ?a)) RET
>>> M-x eval-expression RET (latex-mode)                     RET
>>> M-x eval-expression RET (forward-sexp 200)               RET
>>> M-x eval-expression RET (forward-sexp 500)               RET
>>> M-x eval-expression RET (forward-sexp (point-max))       RET
>> 
>>> In some versions of emacs this does not happen, notably my earlier
>>> Carbon Emacs "GNU Emacs 22.3.1 (i386-apple-darwin9.7.0, Carbon Version
>>> 1.6.0) of 2009-07-26 on gs674-seijiz.local" after loading some lisp
>>> libraries (don't know which), like the ones I have bellow (autopair,
>>> yasnippet).
>> 
>> I can reproduce this slowness even on Emacs 22.3.  It arises because
>> tex-mode wants to be able to signal an error if point is in a containing
>> expression that ends prematurely, so it does a bit of backtracking.
>> (This is the `skip-syntax-backward' call in latex-forward-sexp-1).
>> 
>> I'm not sure what the best way to fix this is, though.
> 

[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5734; Package emacs. (Fri, 03 Aug 2012 02:39:01 GMT) Full text and rfc822 format available.

Message #14 received at 5734 <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> gnu.org>
To: João Távora <joaotavora <at> gmail.com>
Cc: 5734 <at> debbugs.gnu.org
Subject: Re: bug#5734: Fwd: 23.1.94;
	(forward-sexp N) at the very end of large latex-mode buffer takes
	time proportional to N
Date: Fri, 03 Aug 2012 10:30:42 +0800
João Távora <joaotavora <at> gmail.com> writes:

>   What about this? This was the workaround I used in autopair.el.
>   The idea behind is that if one `latex-forward-sexp-1' went
>   nowhere, the next one probably isn't going to. I may be wrong :-)

I've committed this patch to trunk.




bug closed, send any further explanations to 5734 <at> debbugs.gnu.org and joaotavora <at> gmail.com (Joao Tavora) Request was from Chong Yidong <cyd <at> gnu.org> to control <at> debbugs.gnu.org. (Fri, 03 Aug 2012 02:39:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 31 Aug 2012 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 260 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.