Ihor Radchenko <yanta...@posteo.net> writes:

> Doerthous <doerth...@gmail.com> writes:
>
>> For getting properties of an org entry by ID, I currently (org 9.7) use
>> (org-entry-get (org-id-find ID t) PROP), but `org-id-find' seems too
>> slow. So I wonder this there any recommended ways to do this job? 
>>
>> or, maybe we can cache also the marker returned by `org-id-find' in
>> `org-id-locations'?
>
> May you show profiler report detailing what exactly is slow?
> You can save the profile with M-x profiler-report-write-profile from the
> report buffer.

Hi Ihor,

Sorry for the late reply.

I actually done a performance test that day with the following block:

#+begin_src emacs-lisp :cache yes :exports both
  (with-temp-buffer
    (concat
     (x/elp-test-helper `(org-id-find org-entry-get x/org-id-prop)
      (dotimes (i 1000)
        ;; Org-way for retrieve entry property by id:
        (org-entry-get
          (org-id-find '757fe0d4-1f77-46d8-bb84-fa0eefd1f9e0 t) "ID")
          
        ;; A hash table implementation, mapping ID to an other property
        ;; hashtable:
        (x/org-id-prop "ID" '757fe0d4-1f77-46d8-bb84-fa0eefd1f9e0)))))
#+end_src

#+RESULTS:
: org-id-find        1000        6.4504779999  0.0064504779
: org-entry-get      1000        0.0776989999  7.769...e-05
: x/org-id-prop      1000        0.0090050000  9.005...e-06

BTW, let me just demonstrate my motivation for this.

My org notes currently are organized by ID property, and I got a
requirement for retrieving the note's properties by ID. The note
property contains not only those in the property drawer, but also
some special properties computed from the note's content. So I have
to use a nested hashtable to do my job and update those properties
cache manually.

When I was on Org 9.6, the org-entry-get API took POM as its input.
And recently I found it now supports ELE, which is an org-element
parsed node. And the org-element package also introduces some new
APIs, like org-element-cache-store-key. So I'm trying to use these
features to refactor my code to reuse the org-element-cache.

But sadly, as you can see, the test results show that org-entry-get
is still slow than a pure hashtable implementation, even if the
return marker of org-id-find is cached in org-id-locations.

Reply via email to