From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Newsgroups: gmane.emacs.bugs Subject: bug#7089: 23.2; slow ansi-color-apply Date: Thu, 23 Sep 2010 10:15:41 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1285235050 31667 80.91.229.12 (23 Sep 2010 09:44:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 23 Sep 2010 09:44:10 +0000 (UTC) Cc: Alex Schroeder To: 7089@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Sep 23 11:44:07 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OyiLS-0003XV-QD for geb-bug-gnu-emacs@m.gmane.org; Thu, 23 Sep 2010 11:44:03 +0200 Original-Received: from localhost ([127.0.0.1]:53811 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OyiLR-0001EY-HD for geb-bug-gnu-emacs@m.gmane.org; Thu, 23 Sep 2010 05:44:01 -0400 Original-Received: from [140.186.70.92] (port=43201 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OyiLH-0001D6-5x for bug-gnu-emacs@gnu.org; Thu, 23 Sep 2010 05:43:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OyiIY-00078u-34 for bug-gnu-emacs@gnu.org; Thu, 23 Sep 2010 05:41:03 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40419) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OyiIY-00078p-1g for bug-gnu-emacs@gnu.org; Thu, 23 Sep 2010 05:41:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1OyhsQ-0001IP-MG; Thu, 23 Sep 2010 05:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Leo Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 23 Sep 2010 09:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 7089 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.12852331944970 (code B ref -1); Thu, 23 Sep 2010 09:14:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 23 Sep 2010 09:13:14 +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 1Oyhre-0001I7-BZ for submit@debbugs.gnu.org; Thu, 23 Sep 2010 05:13:14 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oyhrc-0001I2-9l for submit@debbugs.gnu.org; Thu, 23 Sep 2010 05:13:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oyhu8-0002Qz-Mn for submit@debbugs.gnu.org; Thu, 23 Sep 2010 05:15:49 -0400 Original-Received: from lists.gnu.org ([199.232.76.165]:49621) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oyhu8-0002Qq-Et for submit@debbugs.gnu.org; Thu, 23 Sep 2010 05:15:48 -0400 Original-Received: from [140.186.70.92] (port=60581 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oyhu6-0006dk-Q1 for bug-gnu-emacs@gnu.org; Thu, 23 Sep 2010 05:15:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oyhu5-0002Q0-AY for bug-gnu-emacs@gnu.org; Thu, 23 Sep 2010 05:15:46 -0400 Original-Received: from ppsw-31.csi.cam.ac.uk ([131.111.8.131]:57880) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oyhu3-0002PN-Pr; Thu, 23 Sep 2010 05:15:44 -0400 X-Cam-AntiVirus: no malware found X-Cam-SpamDetails: not scanned X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Original-Received: from cpc1-cmbg13-0-0-cust596.5-4.cable.virginmedia.com ([86.9.122.85]:62616 helo=Victoria.local) by ppsw-31.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.157]:587) with esmtpsa (PLAIN:sl392) (TLSv1:DHE-RSA-AES128-SHA:128) id 1Oyhu2-0001lE-Ka (Exim 4.72) (return-path ); Thu, 23 Sep 2010 10:15:42 +0100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Thu, 23 Sep 2010 05:14:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:40373 Archived-At: I have found ansi-color-apply very expensive and slow. To test this, do the following (remove-hook 'eshell-output-filter-functions 'eshell-handle-ansi-color) (add-hook 'eshell-preoutput-filter-functions 'ansi-color-apply) and do something in eshell that can output a large coloured text such as: cd /usr/include; ack time where ack is a single file perl script from http://betterthangrep.com/. The CPU usage should shoot up to very high. The following version (after brief testing) seems to be noticeably faster. (defun ansi-color-apply* (string) "A more efficient implementation of `ansi-color-apply' (which see)." (let ((face (car ansi-color-context)) start end fragment escape-sequence) ;; If context was saved and is a string, prepend it. (if (cadr ansi-color-context) (setq string (concat (cadr ansi-color-context) string) ansi-color-context nil)) (with-temp-buffer (insert string) (setq start (point-min-marker)) (goto-char start) (while (re-search-forward ansi-color-drop-regexp nil t) (replace-match "")) (goto-char start) ;; Find the next escape sequence. (while (re-search-forward ansi-color-regexp nil t) (setq end (match-beginning 0)) (when face (put-text-property start end 'ansi-color t) (put-text-property start end 'face face)) (setq start (copy-marker (match-end 0))) (setq escape-sequence (match-string 1)) (replace-match "") (setq face (ansi-color-apply-sequence escape-sequence face))) ;; search for the possible start of a new escape sequence (if (re-search-forward "\033" nil t) (setq end (match-beginning 0) fragment (buffer-substring end (point-max))) (setq end (point-max))) ;; if the rest of the string should have a face, put it there (when face (put-text-property start end 'ansi-color t) (put-text-property start end 'face face)) ;; save context (if (or face fragment) (setq ansi-color-context (list face fragment)) (setq ansi-color-context nil)) (buffer-string)))) Leo