emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Adam Porter <adam@alphapapa.net>, emacs-orgmode@gnu.org
Subject: Re: Asynchronous org-agenda-redo
Date: Sun, 22 Dec 2019 14:54:11 +0800	[thread overview]
Message-ID: <87fthcrgto.fsf@gmail.com> (raw)
In-Reply-To: <878snfsdt7.fsf@alphapapa.net>

> That's a very elegant way to add the threading!

Thanks for kind words.

> The performance penalty
> is noticeable, but the tradeoff could be worth it in some cases, like a
> background agenda refresh on a timer, or after a "remote" edit.  I can
> imagine an org-agenda-refresh-async command that would add that advice
> and remove them in an unwind-protect.

That may be a good way to go. Probably, even refreshing agenda in a
separate copy of agenda buffer, so that the current version remains
usable. 

> The first thing that comes to mind is to set buffer-read-only on each
> buffer before it is scanned, and unset it when done with a buffer.  That
> might not be doable with advice.

This is not enough.
If you accidentally move the point in the buffer being processed by
agenda, the results may be unpredictable (org-agenda-get-* functions
move across the buffer with re-search-forward).

Any ideas how to deal with this?

Best,
Ihor


Adam Porter <adam@alphapapa.net> writes:

> Ihor Radchenko <yantar92@gmail.com> writes:
>
>>>> Asynchronous code is not faster; it's generally slower because of
>>>> yielding and synchronization.
>>
>>> Anyway, I will try to throw yields into agenda code just to check how
>>> bad the performance can degrade.
>>
>> With the following code, org-agenda-redo runs for 21 second on my
>> system, while without threads it is 16 seconds. However, emacs remains
>> responsive during rebuilding agenda!
>>
>> (define-advice org-agenda-redo (:around (oldfun &optional all) make-async)
>>   (make-thread (lambda () (funcall oldfun all)) "org-agenda-redo"))
>> (define-advice org-agenda-skip-eval (:around (oldfun form) make-async)
>>   (thread-join (make-thread (lambda () (funcall oldfun form)) "org-agenda-skip-eval")))
>
> That's a very elegant way to add the threading!  The performance penalty
> is noticeable, but the tradeoff could be worth it in some cases, like a
> background agenda refresh on a timer, or after a "remote" edit.  I can
> imagine an org-agenda-refresh-async command that would add that advice
> and remove them in an unwind-protect.
>
>> The problem, of course, is that touching agenda buffer and org buffers
>> may be risky while org-agenda-redo is running.
>> Wondering if it is possible to block user commands during that time.
>
> The first thing that comes to mind is to set buffer-read-only on each
> buffer before it is scanned, and unset it when done with a buffer.  That
> might not be doable with advice.
>
>

  reply	other threads:[~2019-12-22  6:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-12  8:18 Asynchronous org-agenda-redo Ihor Radchenko
2019-12-12 12:17 ` Adam Porter
2019-12-12 15:46   ` Ihor Radchenko
2019-12-13  6:49     ` Adam Porter
2019-12-13  8:35       ` Ihor Radchenko
2019-12-13  9:39         ` Ihor Radchenko
2019-12-14  4:59           ` Adam Porter
2019-12-22  6:54             ` Ihor Radchenko [this message]
2019-12-24  0:36               ` Adam Porter
2019-12-14  4:50         ` Adam Porter
2019-12-16  7:23           ` Ihor Radchenko
2019-12-16 10:32             ` Adam Porter
2019-12-12 12:51 ` Diego Zamboni
2019-12-12 14:58   ` Ihor Radchenko
2019-12-15 11:56     ` Asynchronous org-babel-tangle (was Re: Asynchronous org-agenda-redo) Diego Zamboni
2019-12-15 13:40       ` Ihor Radchenko
2019-12-15 13:41       ` 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://www.orgmode.org/

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

  git send-email \
    --in-reply-to=87fthcrgto.fsf@gmail.com \
    --to=yantar92@gmail.com \
    --cc=adam@alphapapa.net \
    --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
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

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