emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* spee-up table refresh
@ 2017-01-08 17:28 Thierry Banel
  2017-01-08 23:24 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Thierry Banel @ 2017-01-08 17:28 UTC (permalink / raw)
  To: emacs-orgmode

Re-computing a large table is slow. Hereafter is a test case for a 1000
row table. My computer refreshes it in 44 seconds.

Here is a fast-and-dirty-not-to-be-commited patch which speed-up the
refresh to less than 1 second. I just removed the last 3 lines of
(org-at-table-p).

I don't understand those 3 lines, but everything still works fine
without them (the 688 tests work as expected). Those lines indirectly
call (org-element--cache-put) a quadratic number of times. For a 1000
rows table this is 501500 times (about 1000x1000/2 times).

#+BEGIN_SRC elisp :results none
(defun org-at-table-p (&optional table-type)
  "Non-nil if the cursor is inside an Org table.
If TABLE-TYPE is non-nil, also check for table.el-type tables.
If `org-enable-table-editor' is nil, return nil unconditionally."
  (and
   org-enable-table-editor
   (save-excursion
     (beginning-of-line)
     (looking-at-p (if table-type "[ \t]*[|+]" "[ \t]*|")))
))
;   (or (not (derived-mode-p 'org-mode))
;       (let ((e (org-element-lineage (org-element-at-point) '(table) t)))
;     (and e (or table-type (eq (org-element-property :type e) 'org)))))))
#+END_SRC

Here is a test case.

1- First create a 1000 row table:

#+BEGIN_SRC elisp :results none
  (goto-char (point-max))
  (let ((i 1000))
    (while (> i 0)
      (insert (format "| %4s | |\n" i))
      (setq i (1- i))))
  (insert "#+TBLFM: $2=$1*10\n")
#+END_SRC

2- Then, with point in the table, type C-u C-c *

Regards,
Thierry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: spee-up table refresh
  2017-01-08 17:28 spee-up table refresh Thierry Banel
@ 2017-01-08 23:24 ` Nicolas Goaziou
  2017-01-09 22:27   ` Thierry Banel
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2017-01-08 23:24 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Hello,

> I don't understand those 3 lines

The prevent matching a table below

  #+begin_example
  | I'm not a table |
  #+end_example
  
> without them (the 688 tests work as expected). Those lines indirectly
> call (org-element--cache-put) a quadratic number of times. For a 1000
> rows table this is 501500 times (about 1000x1000/2 times).

Note that recalculating a table is inherently quadratic.

> Here is a test case.
>
> 1- First create a 1000 row table:
>
> #+BEGIN_SRC elisp :results none
>   (goto-char (point-max))
>   (let ((i 1000))
>     (while (> i 0)
>       (insert (format "| %4s | |\n" i))
>       (setq i (1- i))))
>   (insert "#+TBLFM: $2=$1*10\n")
> #+END_SRC
>
> 2- Then, with point in the table, type C-u C-c *

I limited calls to `org-element-at-point'. It should be much faster now.
Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: spee-up table refresh
  2017-01-08 23:24 ` Nicolas Goaziou
@ 2017-01-09 22:27   ` Thierry Banel
  0 siblings, 0 replies; 3+ messages in thread
From: Thierry Banel @ 2017-01-09 22:27 UTC (permalink / raw)
  To: emacs-orgmode

Le 09/01/2017 00:24, Nicolas Goaziou a écrit :

> Note that recalculating a table is inherently quadratic.

Well, on the test-case your change made recalculation linear (which is
good):

|  rows | seconds |
|-------+---------|
|  1000 |     1.5 |
| 10000 |      13 |
| 20000 |      25 |
| 30000 |      37 |

>
>> Here is a test case.
>>
>> 1- First create a 1000 row table:
>>
>> #+BEGIN_SRC elisp :results none
>>   (goto-char (point-max))
>>   (let ((i 1000))
>>     (while (> i 0)
>>       (insert (format "| %4s | |\n" i))
>>       (setq i (1- i))))
>>   (insert "#+TBLFM: $2=$1*10\n")
>> #+END_SRC
>>
>> 2- Then, with point in the table, type C-u C-c *
> I limited calls to `org-element-at-point'. It should be much faster now.
> Thank you.
>

And you did so through an impressively light change: swapping two lines
with a test on `suppress-analysis'.

Thanks and regards.
Thierry

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-09 22:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-08 17:28 spee-up table refresh Thierry Banel
2017-01-08 23:24 ` Nicolas Goaziou
2017-01-09 22:27   ` Thierry Banel

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