* [PATCH] faster org-table-align
@ 2020-05-08 12:50 tbanelwebmin
2020-05-08 13:44 ` Nicolas Goaziou
0 siblings, 1 reply; 3+ messages in thread
From: tbanelwebmin @ 2020-05-08 12:50 UTC (permalink / raw)
To: emacs-orgmode
`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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] faster org-table-align
2020-05-08 12:50 [PATCH] faster org-table-align tbanelwebmin
@ 2020-05-08 13:44 ` Nicolas Goaziou
2020-05-08 14:56 ` tbanelwebmin
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2020-05-08 13:44 UTC (permalink / raw)
To: tbanelwebmin; +Cc: emacs-orgmode
Hello,
tbanelwebmin <tbanelwebmin@free.fr> writes:
> `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)))
Good catch! I applied a similar change in master. Let me know how it
goes.
Thank you!
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] faster org-table-align
2020-05-08 13:44 ` Nicolas Goaziou
@ 2020-05-08 14:56 ` tbanelwebmin
0 siblings, 0 replies; 3+ messages in thread
From: tbanelwebmin @ 2020-05-08 14:56 UTC (permalink / raw)
To: emacs-orgmode
Le 08/05/2020 à 15:44, Nicolas Goaziou a écrit :
> Hello,
>
> tbanelwebmin <tbanelwebmin@free.fr> writes:
>
>> `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)))
> Good catch! I applied a similar change in master. Let me know how it
> goes.
>
> Thank you!
>
> Regards,
>
I ran again my benchmark with your patch. The Emacs profiler is not
accurate enough to tell which one among `mapcar' and `cl-loop' is
best. Anyway, your patch is perfect!
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-08 14:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08 12:50 [PATCH] faster org-table-align tbanelwebmin
2020-05-08 13:44 ` Nicolas Goaziou
2020-05-08 14:56 ` tbanelwebmin
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.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).