feat: improve triples matching performance#534
Merged
samuel-bustamante merged 1 commit intorudof-project:masterfrom Mar 12, 2026
Merged
Conversation
9a960ed to
fe2c64d
Compare
fe2c64d to
a1297db
Compare
Collaborator
|
Great optimization, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi,
The current triples matching algorithm was an overkill since it needs to retrieve all the triples always. I have improved that by utilizing the correct index function based on what's available. The performance gains are almost 1000x for large graphs in cases like SHACL validation.
Summary:
File changed:
rudof_rdf/src/rdf_impl/in_memory_graph.rsThe new
triples_matchingdispatches to the bestoxrdf::Graphindex basedon which of the three positions carry a concrete value vs a wildcard (
Any):(S, P, O)graph.contains(triple_ref)(S, P, ?)graph.objects_for_subject_predicate(s, p)(S, ?, ?)graph.triples_for_subject(s)(?, P, ?)graph.triples_for_predicate(p)(?, P, O)graph.subjects_for_predicate_object(p, o)(?, ?, O)graph.triples_for_object(o)(S, ?, O)triples_for_subject(s)+ filter by O(?, ?, ?)graph.iter()