emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: tbanelwebmin <tbanelwebmin@free.fr>
To: emacs-orgmode@gnu.org
Subject: [PATCH] faster org-table-align
Date: Fri, 8 May 2020 14:50:44 +0200	[thread overview]
Message-ID: <00ea3013-c768-cdd9-3385-980bba796460@free.fr> (raw)

`org-table-align' may benefit from recent `org-table-to-lisp'

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

             reply	other threads:[~2020-05-08 13:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-08 12:50 tbanelwebmin [this message]
2020-05-08 13:44 ` Nicolas Goaziou
2020-05-08 14:56   ` tbanelwebmin

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:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=00ea3013-c768-cdd9-3385-980bba796460@free.fr \
    --to=tbanelwebmin@free.fr \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [PATCH] faster org-table-align' \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:


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).