Speed up extraction of global props, headlines, and title #1061
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation for this change
Org-roam takes a long time to process files. In addition, big files (10000+ lines) can take several seconds to process after it is modified. This becomes unbearable for eg. habit (
org-habit
) tracking files.This PR introduces some optimizations:
org-element-parse-buffer
org-roam--extract-headlines
: Useorg-map-region
andorg-entry-get
instead oforg-element-parse-buffer
.org-roam--extract-titles-headline
: Find the first headline withorg-outline-regexp-bol
instead of usingorg-element-parse-buffer
.org-collect-keywords
which is a lot faster as it also avoidsorg-element-parse-buffer
. (As it is a relatively new function in Org, added in April 2020, I have kept the previous implementation if it's not present.)Performance comparison
vocab.org
is an Org file with 14795 lines (1052 headings).I'm running this on a Ryzen 1400 CPU.
Before:
After:
From 5 seconds down to 0.15 seconds.