Org-mode mailing list
 help / color / mirror / Atom feed
From: Maxim Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] Bug: fragile org refile cache
Date: Fri, 30 Apr 2021 23:56:27 +0700
Message-ID: <s6hcrs$la3$1@ciao.gmane.io> (raw)
In-Reply-To: <877dklxecq.fsf@localhost>

On 29/04/2021 23:08, Ihor Radchenko wrote:
> Did you do any benchmarks? I just tried
> 
> Outline path without cache:

I have expanded your tests to make them more close to org-get-outline-path

org-get-outline-path without cache
| 5.459114059 | 12 | 1.2053580009999987 |
org-get-outline-path with cache
| 2.166378543 |  5 | 0.5011187770000003 |

Custom code to track outline path during scan
| 0.718288205 | 4 | 0.4005034349999992 |
The same without (org-trim ...) stuff
| 0.208798040 | 0 |                0.0 |

 From my point of view avoiding org-get-outline-path allows to 
significantly improve performance. Removing cookies, etc. is far from 
being negligible.

Test file is org-manual.org with 404 headings. Since it is not so much, 
I set minimal CPU frequency.

Notice that outline cache is cleared before each scan to simulate the 
case when org-goto is invoked just after emacs start or after 
adding/removing some lines in the beginning of the file. Actually it is 
a problem of outline cache that it easily became stale due to e.g. extra 
line close to buffer start.

Details:

#+begin_example bash
for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ;
do
     echo powersave >"$i" ;
done
#+end_example

#+begin_src elisp
   (byte-compile-file (expand-file-name "~/src/emacs/org-mode/lisp/org.el"))
   (defun nm-count-headings (headings)
     (let ((n 0))
       (dolist (h headings)
	(setq n (+ n (length h))))
       (list (length headings) n)))
#+end_src

#+RESULTS:
: nm-count-headings

#+begin_src elisp
   (defun ir-tst-scan (buffer use-cache)
     (with-current-buffer buffer
       (goto-char 1)
       (let ((result nil))
	(while (re-search-forward "^\\*+[ \t]" nil t)
	  (beginning-of-line)
	  (let ((case-fold-search nil))
	    (looking-at org-complex-heading-regexp))
	  (push (org-get-outline-path t use-cache) result)
	  (end-of-line))
	result)))
   (byte-compile 'ir-tst-scan)
   (mapcar
    (lambda (use-cache)
      (let ((headings))
        (append
	(list use-cache)
	(benchmark-run 10
	  (progn
	    (setq org-outline-path-cache nil)
	    (setq headings
		  (ir-tst-scan "org-manual.org" use-cache))))
	(nm-count-headings headings))))
    '(nil t))
#+end_src

#+RESULTS:
| nil | 5.459114059 | 12 | 1.2053580009999987 | 404 | 1069 |
| t   | 2.166378543 |  5 | 0.5011187770000003 | 404 | 1069 |

| use-cache | benchmark | |                   | headings | outline 
components |

#+begin_src elisp
   (defun nm-tst-scan (buffer clean-headers)
     (with-current-buffer buffer
       (goto-char 1)
       (let ((result nil))
	(let ((outline-path))
	  (while (re-search-forward "^\\*+[ \t]" nil t)
	    (beginning-of-line)
	    (let ((case-fold-search nil))
	      (looking-at org-complex-heading-regexp))
	    (let ((heading (match-string-no-properties 4))
		  (heading-level (length (match-string-no-properties 1))))
	      (while (and outline-path (<= heading-level (caar outline-path)))
		(pop outline-path))
	      (push (cons heading-level
			  (if (not heading)
			      ""
			    (if (not clean-headers)
				heading
			      (org-trim
			       (org-link-display-format
				(replace-regexp-in-string
				 "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
				 heading))))))
		    outline-path))
	    (end-of-line)
	    (push (mapcar #'cdr outline-path) result)))
	result)))
   (byte-compile 'nm-tst-scan)
   (mapcar
    (lambda (clean-headers)
      (let ((headings))
        (append
	(list clean-headers)
	(benchmark-run 10
	  (progn
	    (setq org-outline-path-cache nil)
	    (setq headings
		  (nm-tst-scan "org-manual.org" clean-headers))))
	(nm-count-headings headings))))
    '(nil t))
#+end_src

#+RESULTS:
| nil | 0.20879804000000002 | 0 |                0.0 | 404 | 1069 |
| t   |         0.718288205 | 4 | 0.4005034349999992 | 404 | 1069 |

| clean-headers | benchmark |   |                    | headings | 
outline components |



  parent reply	other threads:[~2021-04-30 17:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28 16:09 Maxim Nikulin
2021-04-29  0:50 ` Samuel Wales
2021-04-29  1:29   ` Ihor Radchenko
2021-04-29  1:34     ` Samuel Wales
2021-04-29 12:45       ` Maxim Nikulin
2021-04-29 14:12         ` Ihor Radchenko
2021-04-29 15:04           ` Maxim Nikulin
2021-04-29 16:08             ` Ihor Radchenko
2021-04-29 16:51               ` Maxim Nikulin
2021-04-30 16:56               ` Maxim Nikulin [this message]
2021-05-01 14:48               ` Maxim Nikulin
2021-05-02  6:59                 ` Ihor Radchenko
2021-05-04 16:55                   ` Maxim Nikulin
2021-05-05  0:53                     ` Ihor Radchenko
2021-04-29 13:30       ` Ihor Radchenko
2021-04-29 19:17         ` Tim Cross
2021-04-29 22:43           ` Samuel Wales
2021-05-02  7:03           ` Ihor Radchenko

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://orgmode.org

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

  git send-email \
    --in-reply-to='s6hcrs$la3$1@ciao.gmane.io' \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

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

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git