From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Artur Malabarba Newsgroups: gmane.emacs.devel Subject: Re: Lazy printing in tabulated-list-mode Date: Mon, 4 May 2015 11:46:28 +0100 Message-ID: References: Reply-To: bruce.connor.am@gmail.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1430736406 15060 80.91.229.3 (4 May 2015 10:46:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 4 May 2015 10:46:46 +0000 (UTC) Cc: emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 04 12:46:46 2015 Return-path: Envelope-to: ged-emacs-devel@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 1YpDtc-0004oX-Bg for ged-emacs-devel@m.gmane.org; Mon, 04 May 2015 12:46:44 +0200 Original-Received: from localhost ([::1]:33581 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpDtb-0002je-Rx for ged-emacs-devel@m.gmane.org; Mon, 04 May 2015 06:46:43 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpDtO-0002i6-TT for emacs-devel@gnu.org; Mon, 04 May 2015 06:46:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YpDtN-0000UC-P5 for emacs-devel@gnu.org; Mon, 04 May 2015 06:46:30 -0400 Original-Received: from mail-lb0-x22b.google.com ([2a00:1450:4010:c04::22b]:36600) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpDtN-0000U5-C8 for emacs-devel@gnu.org; Mon, 04 May 2015 06:46:29 -0400 Original-Received: by lbbqq2 with SMTP id qq2so101729163lbb.3 for ; Mon, 04 May 2015 03:46:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=CzifjlMUKsT7YsBFijj1lnWxklxk+XnJbLcmo44PWuc=; b=YK/gej3J2P44gRFh64UBfw9zydZWd719z0spLanT8dK8z9Mrx157ESlNwSNDzWFsNe t2xft0ilMFT8/pi60EhQa5YG/ZdAs94cGNdFgLV8RBWk7dIeBkz7JCu+iliana9UKaWk ImdsiRQoPoka/JKLFtmxTpTm644t7Wu0AowYjhS3qBmcQz54hgkOlnKljuLWINnNt2dB gGJKuuXfEvogu32ZnN5aVT7Xb3ozo9veObOrX5oyy3IddpCzQ9EmOnTwPSCJjsVn445F 83WNMbW3olM50Hr12BzrkCny53E26RLlzfW9fLpgc9LVfiVwTfxgV1gHRchiL4JV9ktq nQpw== X-Received: by 10.152.203.233 with SMTP id kt9mr19097276lac.21.1430736388508; Mon, 04 May 2015 03:46:28 -0700 (PDT) Original-Received: by 10.25.150.1 with HTTP; Mon, 4 May 2015 03:46:28 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: efg3zDmkAxcRpu18R3g26w-Jqug X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::22b X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:186178 Archived-At: With some investigation, I managed to pinpoint some small problems in -print-col: propertize and concat. By replacing the calls to `propertize' with insert+put-text-properties, and by removing the `concat', the following patch speeds up printing by ~ 20%. The only functional difference is that the help-echo property of an entry's column will be "entry-content" instead of "column-name: entry-content" (the former seems redundant to me anyway). I get another 50% speed-up on top of that if I remove all `put-text-property' calls. :-D I won't do that of course, but at least it shows where most of the work is going. Subject: [PATCH] * lisp/emacs-lisp/tabulated-list.el: Speed optimizations (tabulated-list-print-col): Prefer `put-text-property' to `propertize'. Avoid `concat'. --- lisp/emacs-lisp/tabulated-list.el | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el index b12edc8..173e253 100644 --- a/lisp/emacs-lisp/tabulated-list.el +++ b/lisp/emacs-lisp/tabulated-list.el @@ -346,6 +346,14 @@ of column descriptors." beg (point) `(tabulated-list-id ,id tabulated-list-entry ,cols)))) +(defmacro tabulated-list--insert-space-string (s prop value) + "Insert a propertized string of size S composed of spaces. +Put property PROP with VALUE." + `(let* ((size ,s) + (string (make-string size ?\s))) + (put-text-property 0 size ,prop ,value string) + (insert string))) + (defun tabulated-list-print-col (n col-desc x) "Insert a specified Tabulated List entry at point. N is the column number, COL-DESC is a column descriptor (see @@ -361,7 +369,6 @@ Return the column number after insertion." (right-align (plist-get props :right-align)) (label (if (stringp col-desc) col-desc (car col-desc))) (label-width (string-width label)) - (help-echo (concat (car format) ": " label)) (opoint (point)) (not-last-col (< (1+ n) (length tabulated-list-format)))) ;; Truncate labels if necessary (except last column). @@ -372,22 +379,24 @@ Return the column number after insertion." (setq label (bidi-string-mark-left-to-right label)) (when (and right-align (> width label-width)) (let ((shift (- width label-width))) - (insert (propertize (make-string shift ?\s) - 'display `(space :align-to ,(+ x shift)))) + (tabulated-list--insert-space-string + shift 'display `(space :align-to ,(+ x shift))) (setq width (- width shift)) (setq x (+ x shift)))) (if (stringp col-desc) - (insert (if (get-text-property 0 'help-echo label) - label - (propertize label 'help-echo help-echo))) + (if (get-text-property 0 'help-echo label) + (insert label) + (let ((op (point))) + (insert label) + (put-text-property op (point) 'help-echo label))) (apply 'insert-text-button label (cdr col-desc))) (let ((next-x (+ x pad-right width))) ;; No need to append any spaces if this is the last column. (when not-last-col (when (> pad-right 0) (insert (make-string pad-right ?\s))) - (insert (propertize - (make-string (- next-x x label-width pad-right) ?\s) - 'display `(space :align-to ,next-x)))) + (tabulated-list--insert-space-string + (- next-x x label-width pad-right) + 'display `(space :align-to ,next-x))) (put-text-property opoint (point) 'tabulated-list-column-name name) next-x))) -- 2.3.7