From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id WPLSGUJZtV4hTgAA0tVLHw (envelope-from ) for ; Fri, 08 May 2020 13:06:10 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id SA+lA09ZtV4QIQAA1q6Kng (envelope-from ) for ; Fri, 08 May 2020 13:06:23 +0000 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B01FF94116E for ; Fri, 8 May 2020 13:06:20 +0000 (UTC) Received: from localhost ([::1]:40022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX2hn-0002e7-L4 for larch@yhetil.org; Fri, 08 May 2020 09:06:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX2Sr-0005tr-BN for emacs-orgmode@gnu.org; Fri, 08 May 2020 08:50:53 -0400 Received: from smtp1-g21.free.fr ([2a01:e0c:1:1599::10]:34626) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX2So-0001Uk-E9 for emacs-orgmode@gnu.org; Fri, 08 May 2020 08:50:52 -0400 Received: from [IPv6:2a01:e35:1398:10f0:58bd:508d:d40b:2fb0] (unknown [IPv6:2a01:e35:1398:10f0:58bd:508d:d40b:2fb0]) by smtp1-g21.free.fr (Postfix) with ESMTPS id 4BD43B0053D for ; Fri, 8 May 2020 14:50:45 +0200 (CEST) From: tbanelwebmin Subject: [PATCH] faster org-table-align To: emacs-orgmode@gnu.org Message-ID: <00ea3013-c768-cdd9-3385-980bba796460@free.fr> Date: Fri, 8 May 2020 14:50:44 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Received-SPF: none client-ip=2a01:e0c:1:1599::10; envelope-from=tbanelwebmin@free.fr; helo=smtp1-g21.free.fr X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 X-Spam-Score: 0.49 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 2001:470:142::17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Scan-Result: default: False [0.49 / 13.00]; GENERIC_REPUTATION(0.00)[-0.49891782810926]; MX_INVALID(1.00)[cached]; DWL_DNSWL_FAIL(0.00)[2001:470:142::17:server fail]; R_SPF_ALLOW(-0.20)[+ip6:2001:470:142::/48:c]; FREEMAIL_FROM(0.00)[free.fr]; TO_DN_NONE(0.00)[]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.10), country: US(-0.00), ip: 2001:470:142::17(-0.50)]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_IN_DNSWL_FAIL(0.00)[2001:470:142::17:server fail]; RCVD_TLS_LAST(0.00)[]; R_DKIM_NA(0.00)[]; ASN(0.00)[asn:22989, ipnet:2001:470:142::/48, country:US]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_FROM(0.00)[larch=yhetil.org]; ARC_NA(0.00)[]; RCVD_COUNT_FIVE(0.00)[5]; FROM_NEQ_ENVFROM(0.00)[tbanelwebmin@free.fr,emacs-orgmode-bounces@gnu.org]; FROM_HAS_DN(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[emacs-orgmode@gnu.org]; DMARC_NA(0.00)[free.fr]; HAS_LIST_UNSUB(-0.01)[]; RCPT_COUNT_ONE(0.00)[1]; MIME_TRACE(0.00)[0:+]; FORGED_SENDER_MAILLIST(0.00)[] X-TUID: Pp62DjEgWc56 `org-table-align' may benefit from recent `org-table-to-lisp' speed-up. The current code contains the following lines in org-table.el. They parse the table into a Lisp structure, which is precisely what `org-table-to-lisp' is supposed to do. (fields (mapcar (lambda (l) (and (not (string-match-p org-table-hline-regexp l)) (org-split-string l "[ \t]*|[ \t]*"))) (split-string (buffer-substring beg end) "\n" t))) Just replace them by a call to `org-table-to-lisp': (fields (cl-loop for row in (org-table-to-lisp) collect (and (listp row) row))) I made a benchmark on a large table (10000 rows, 6 columns). Adding a column, then removing it, M-S-right M-S-left. I measured time and memory with profiler-*, taking care to call `garbage-collect' beforehand. Conclusions: - `org-table-align' is faster, overall operation is faster - there is much less garbage collection - memory allocation is significantly lower | | current | new | % | |----------------------------------+-----------+-----------+-----| | org-table-align CPU samples | 1313 | 1102 | 16. | | overall CPU samples | 2040 | 1628 | 20. | | GC CPU samples | 4283 | 2609 | 39. | | overall allocated bytes | 622087730 | 272436087 | 56. | | org-table-align allocated bytes | 445910318 | 146646065 | 67. | #+TBLFM: $4=100*($-2-$-1)/$-2;f0 Note: running twice the same bench yields slightly different results. Have fun Thierry