Maxim Nikulin writes: > Though I still have not tested the patch, I think, it is an improvement > and it is helpful in its current form. I am unable to tell if it follows > code style. FYI, this patch may also slightly improve the performance of org-get-outline-path. > My bad, you mentioned tags earlier, but I grepped org-agenda.el only. > My new idea is that org-get-tags may have its own cache as well. Unsure > if it should be tried. I am trying it now ;) No benchmarks yet, but it also provides a subjective improvement. However, I am trying to reuse org-element-cache for tags. org-element-cache is smart enough to update itself partially on buffer changes. However, there are (known) bugs in org-element-cache. I managed to track down some, but still need to test thoughtfully before submitting upstream. > Did you just replace gethash by avl-tree? Yes > Likely my idea is based on a > wrong assumption. I hoped that having positions of headers it is > possible to avoid jumps (goto-char ...) preceded or followed by regexp > matching almost completely. Previous header for arbitrary initial > position can be found using binary search through structure obtained > during scan. Sorry, I cannot follow what you mean. The call to goto-char in org-up-heading-safe is required by function docstring - we need to move point to the parent heading. >> + (re-search-backward >> + (format "^\\*\\{1,%d\\} " level-up) nil t) >> + (funcall outline-level)))) > > Unsure concerning the following optimization from the point of > readability and reliability in respect to future modifications. Outline > level can be derived from the length of matched string without the > funcall requiring extra regexp. I am not sure here. outline-level also consults outline-heading-alist, though I found no references to that variable in Org mode code. Otherwise, outline-level already reuses match-data. There is no regexp matching there. P.S. I just found that hash-tables are created by reference, so we need to call make-hash-table separately in each buffer with cache. Updated patch attached.