emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Maxim Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] Use cache in org-up-heading-safe
Date: Wed, 5 May 2021 23:40:16 +0700	[thread overview]
Message-ID: <s6uhpi$kek$1@ciao.gmane.io> (raw)
In-Reply-To: <874kfieduh.fsf@localhost>

On 04/05/2021 22:08, Ihor Radchenko wrote:
> While testing another patch for agenda fontification, I noticed that
> agenda can spend up to half!! time doing org-up-heading-safe. Mostly
> inside queries for inherited tags and properties.
> I managed to make org-up-heading-safe up to 50x faster using position
> cache.

I have not tested the patch due to I do not use agenda. My interest was 
stimulated solely by my attempts to make org-refile-get-targets faster.

I consider it as an improvement. I have noticed the only thing that must 
be fixed: comments with old variant of the function. Reaction to my 
other comments is optional.

In org-agenda.el org-up-heading-safe function is called only from 
org-find-top-headline. So the purpose of the dance with backward 
searches is to get top level headings. My expectation is that scan 
through the whole buffer and storing result in a structure that allows 
binary search of position (array, red-black tree, etc) may be even faster.

Alternatively lazily obtained position of top heading could be stored in 
cache to reduce number of iterations on org-find-top-line.

> +    (let ((level-cache (gethash (point) org--up-heading-cache)))
> +      (if (and level-cache
> +               (eq (buffer-chars-modified-tick) org--up-heading-cache-tick))

If buffer-chars-modified-tick is faster than gethash then reordering 
might result in very slight improvement of performance.

> +            ;; Parent is inside accessible part of the buffer.
> +            (progn (goto-char level-cache)
> +                   (funcall outline-level)))

I do not see any reason why outline level can not be cached in pair with 

> +          (let (result)
> +            (setq result

I am not a lisp guru, so from my point of view this can be reduced to
(let ((result ...

> +                        (format "^\\*\\{1,%d\\} " level-up) nil t)

\t as an alternative to " " is used in org-refile.el,
e.g. "^\\*+[ \t]+". Unsure which variant is canonical one and I see that 
regexp is taken from original function, so no regression is expected.

> +;; (defun org-up-heading-safe ()
> +;;   "Move to the heading line of which the present line is a subheading.

Clean-up here is required, other notes may be ignored.

  reply	other threads:[~2021-05-05 17:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04 15:08 [PATCH] Use cache in org-up-heading-safe Ihor Radchenko
2021-05-05 16:40 ` Maxim Nikulin [this message]
2021-05-06 14:34   ` Ihor Radchenko
2021-05-06 17:02     ` Maxim Nikulin
2021-05-07  2:08       ` Ihor Radchenko
2021-05-08 11:28         ` Maxim Nikulin
2021-05-10 15:14           ` Ihor Radchenko
2021-05-15 11:58         ` Bastien
2021-05-16  6:15 ` Bastien
2021-05-16  6:36   ` Ihor Radchenko
2021-05-16  8:53     ` Bastien

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='s6uhpi$kek$1@ciao.gmane.io' \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).