From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Andreas Gustafsson <gson@gson.org>
Cc: 16786@debbugs.gnu.org
Subject: bug#16786: 24.2; PostScript file with long lines locks up UI
Date: Mon, 17 Feb 2014 21:15:54 -0500 [thread overview]
Message-ID: <jwvzjlpi377.fsf-monnier+emacsbugs@gnu.org> (raw)
In-Reply-To: <21250.32840.43915.833076@guava.gson.org> (Andreas Gustafsson's message of "Mon, 17 Feb 2014 23:34:00 +0200")
> (progn
> (switch-to-buffer "test")
> (insert (make-string 100000 97))
> (ps-mode)
> )
For this test, the main bottleneck seems to be the
("([^()\n%]*\\|[^()\n]*)" . font-lock-warning-face)
rule in ps-mode-font-lock-keywords-1. The problem is the second half of
the regexp, which will take O(N) time to fail to match at a particular
position and which will try matching at every buffer position, for
a total of O(N^2).
This can be fixed by anchoring the search, e.g. with the patch below.
Of course, a small variation of the above test leads to
other bottlenecks.
Stefan
=== modified file 'lisp/progmodes/ps-mode.el'
--- lisp/progmodes/ps-mode.el 2014-01-08 18:28:43 +0000
+++ lisp/progmodes/ps-mode.el 2014-02-18 02:10:59 +0000
@@ -220,7 +220,8 @@
(ps-mode-match-string-or-comment
(1 font-lock-comment-face nil t)
(2 font-lock-string-face nil t))
- ("([^()\n%]*\\|[^()\n]*)" . font-lock-warning-face)
+ ("\\(([^()\n%]*\\)\\|\\(?:^\\|[()]\\)\\(?1:[^()\n]*)\\)"
+ (1 font-lock-warning-face))
("[\200-\377]+" (0 font-lock-warning-face prepend nil)))
"Subdued level highlighting for PostScript mode.")
next prev parent reply other threads:[~2014-02-18 2:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-17 21:34 bug#16786: 24.2; PostScript file with long lines locks up UI Andreas Gustafsson
2014-02-18 0:55 ` Glenn Morris
2014-02-18 2:15 ` Stefan Monnier [this message]
2020-08-13 10:38 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvzjlpi377.fsf-monnier+emacsbugs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=16786@debbugs.gnu.org \
--cc=gson@gson.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).