[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Bug: fragile org refile cache
From: |
Ihor Radchenko |
Subject: |
Re: [PATCH] Bug: fragile org refile cache |
Date: |
Sun, 02 May 2021 14:59:44 +0800 |
Maxim Nikulin <manikulin@gmail.com> writes:
> Some additions. org-outline-path-cache is used solely by
> org-refile-get-targets (maybe there are some calls in other packages)
> but it efficiency is questionable. It was not clear for me earlier that
> the cache is reset before each scan through a buffer. So if
> org-refile-use is disabled, org-outline-path-cache from previous run of
> org-refile or org-goto is not used as well. A query to
> org-outline-path-cache requires at least one backward search and hash
> lookup. During sequential scan in org-refile-get-targets it is enough to
> have previous heading path to update it when new heading is found. I
> think, org-outline-path-cache should be deprecated.
At least helm-org-ql and helm-org are using `org-get-outline-path' with
cache. I do think it is useful. Though, indeed, not as fast as
single-pass scan. Probably, we can rewrite the code of
`org-get-outline-path' instead of deprecating it?
>> Just cleanup heading text:
>
> I have realized what is wrong with this benchmark. It runs so fast
> because it matches no headings, so it never spent time for cleaning them up.
Oh. You are right. I tested with fixed benchmark and it is indeed much slower.
> On 29/04/2021 21:12, Ihor Radchenko wrote:
>> For the cleaned heading text, I do not think that re-calculating the
>> heading text on each change is a good idea. It may degrade typing
>> latency. Yet, an acceptable approach could be simply invalidating cache
>> for the changed headings. Then, outline paths can be re-calculated on
>> changed headings when needed.
>
> I agree that it is enough to invalidate cleaned heading on edit to
> refresh it in org-refile-get-targets. On the other hand, I still prefer
> text properties since they could be fetched even if some lines have been
> added or removed before. Position-based cache is useless in such cases.
Note that `org-refresh-category-properties' is using pretty much same
idea. However, there is no automatic invalidation and one needs to run
org-refresh-category-properties to ensure that cache is up to date.
Alternatively, markers can be used here. They will not be invalidated by
changes in buffer.
> Concerning typing latency, it should be postponed and resumed when no
> new edits is performed for certain period of time (~1s). However I am
> unsure if it is possible to accurately track all affected lines since
> later changes can add/remove lines before the line scheduled for
> invalidation.
As one option, we can accumulate the changed regions in some variable
and process them on timer. As I remember, org-element-cache is already
doing something similar. In fact, org-element-cache might be modified to
handle outline-path as well. The problem is that org-element-cache has
some difficult bugs. I tried using it multiple times and ran into issues
I was not able to debug. I may work on this in future.
Best,
Ihor