Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the readme for the metadata part ? #149

Open
Cletip opened this issue Sep 25, 2022 · 4 comments
Open

Update the readme for the metadata part ? #149

Cletip opened this issue Sep 25, 2022 · 4 comments

Comments

@Cletip
Copy link

Cletip commented Sep 25, 2022

I was looking for how to use metadata in a good way for performance.

I was thinking about this part
"Functions of interest:

vulpea-meta - function to get metadata from NOTE-OR-ID. In most cases you should not use this function unless performance is important. In this case, take a look at bang functions, e.g. vulpea-meta-get!"

I do believe that in the end, from what I understood from the code, most of the functions boil down to "vulpea-buffer-meta-X" style functions.
So I thought, according to the readme, that there was a difference between the functions. But actually, I think not ^^

@d12frosted
Copy link
Owner

They are different. Bang variants accept metadata as their argument.

vulpea/vulpea-meta.el

Lines 91 to 107 in f74575e

(defun vulpea-meta-get (note-or-id prop &optional type)
"Get value of PROP for NOTE-OR-ID.
Result depends on TYPE:
- raw - org element object
- string (default) - an interpreted object (without trailing
newline)
- number - an interpreted number
- link - path of the link (either ID of the linked note or raw link)
- note - linked `vulpea-note'
- symbol - an interned symbol.
If the note contains multiple values for a given PROP, the first
one is returned. In case all values are required, use
`vulpea-meta-get-list'."
(vulpea-buffer-meta-get! (vulpea-meta note-or-id) prop type))

You see, vulpea-meta-get actually parses metadata using vulpea-meta and then passes it to vulpea-buffer-meta-get!.

Parsing metadata is not that expensive, but is not free. So if you want to read multiple values from the metadata list, you better parse metadata once using vulpea-meta and then use it to access needed values. For example, I use it in vino:

https://github.com/d12frosted/vino/blob/0ddf2268a716165c05efe1282269772e35415ab0/vino.el#L632-L670

@Cletip
Copy link
Author

Cletip commented Sep 25, 2022

Oh right, I didn't quite understand. I thought the function was the same thing in the end, because one refers to the other (I had looked at how it was made). But in fact, one refers to the other WITH another, hence the difference in performance you mention. Okay, I just figured it out.

I had a little trouble understanding, because the readme have"vulpea-meta-get!" and not "vulpea-meta-get", and knowing that other function with "!" existed, I just thought that one was more efficient than the other.

Thanks you a lot for your answer.

@d12frosted
Copy link
Owner

You're welcome. Thanks for reading README. I think I need to revamp some sections to make them more clear and reflect some of the latest changes.

@Cletip
Copy link
Author

Cletip commented Sep 26, 2022

Np.
By the way, I find your readme particularly well done: there are many examples and I find it well ordered. If I can make a criticism, I find that the part about metadata is "separate", which may be confusing. Well, this is only my opinion.

Keep me informed about the moddifications of the readme if you make some change, you will have an external opinion ^^

I don't close the issue, but you can do it if you want ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants