Hi Org, I would like to propose adding support of storing headlines in org-element-cache. Currently, org-element-cache only stores elements within individual sections. Storing headlines in cache would open various possibilities to improve Org performance: tag inheritance, property inheritance, category queries, id lookup, refile targets, agenda views, etc could all make use of cache. I am not proposing a mere idea, but have an actual working (WIP) code in: https://github.com/yantar92/org. Also, I am attaching a reference patch for org-element.el (the actual branch contains more changes). Some preliminary benchmarks: 1. Complex agenda - with cache: 12.165218664 sec - without cache: 16.703388763 sec 2. Tangling org file with many (570) code blocks: - with cache: 2.886041933 sec - without cache: 6.093907514 sec 3. Archiving heading from a huge org file with many categories - with cache: 0.6030461106 sec - without cache: 1.0111324396 sec 4. Complex search query in a huge org file: - with cache (via org-element-cache-map): 0.41087909697 sec - without cache (via org-ql): 1.07440562674 sec TBD. org-id lookups and org-refile-cache ----- Moreover, the cache can persist across Emacs sessions, so we do not need to care about initial cache population. See org-element-cache-persistent and org-element-cache-path. ----- The current state of the branch is satisfactory and I am able to use it daily in my own system. However, the cache code is notoriously difficult to debug. The original cache implementation has several bugs to start with. While fixing those, I kept seeing more bugs for a very long time. I am not yet sure that the new code is completely bug-free, though I do not see issues anymore in my setup. ---- If there is any interest in merging this work to Org, I will need the community help to catch any leftover bugs. The cache is now supplied with self-consistency checks that can catch errors and report backtrace. The self-consistency checks are enabled by default for now. Any issues will be reported as Emacs warnings. See org-element--cache-self-verify, org-element--cache-self-verify-frequency, org-element--cache-diagnostics-level, and org-element--cache-diagnostics-ring-size for details. ---- Note that self-consistency checks do slow down the cache. Setting org-element--cache-self-verify to nil will showcase the true performance. However, I am not confident enough in the code to disable self-checks by default. ----- Also, I have made several changes to org parser and org API in order to make cache more useful. If there are any objections to the changes, I would like to hear them. ----- 1. I introduced a new element: org-data. In a way, org-data is already used as a placeholder element in org-element-parse-buffer. I extended the idea further and made org-data contain actual properties. Similar to headline elements, org-data contains property list with contents of the top property drawer. Also, category parser not lives inside org-element, unlike original implementation from org.el that had little interaction with org-element API. 2. I added new standard properties to Org elements: :robust-begin, :robust-end, :cached, :mode, :org-element--cache-sync-key, and :granularity. They greatly reduced complexity of cache implementation. 3. headline/org-data properties are now aware about accumulated property values (PROPERTY/PROPERTY+ style). PROPERTY+ lines of the property drawers are now all merged into :PROPERTY headline/org-data element property. 4. org-element-at-point is now guaranteed to return the correct :parent property all the way up to org-data. org-element-at-point now accepts an extra argument preventing it from synchronising the cache. 5. New function: org-element-at-point-no-context. It behaves similar to old org-element-at-point - :parent properties are not guaranteed to be correct. 6. New function: org-element-cache-map. It is similar to org-element-map, but operates on cache. Looking forward for the feedback. Best, Ihor