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

perf: reuse sh:in nodeSet #130

Merged
merged 4 commits into from
Apr 16, 2024
Merged

perf: reuse sh:in nodeSet #130

merged 4 commits into from
Apr 16, 2024

Conversation

giacomociti
Copy link
Contributor

This change boosts validation of sh:in constraints with long lists of allowed values.

The existing implementation recreates the set of allowed nodes again and again, for each value to be validated.
With the proposed change, the node set is created only once.

To appreciate the performance gain, you may try a shapes graph like this, having a constraint with a huge list of municipalities. Try to validate a few observations

(remember to add the target declaration in the shapes graph):

<https://energy.ld.admin.ch/elcom/electricityprice/shape> <http://www.w3.org/ns/shacl#targetClass> <https://cube.link/Observation>  . ```

Copy link

changeset-bot bot commented Apr 13, 2024

🦋 Changeset detected

Latest commit: 1329680

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
rdf-validate-shacl Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines 136 to 144
const inNode = constraint.getParameterValue(sh.in)
if (!constraint.nodeSets) {
constraint.nodeSets = new TermMap()
}
let nodeSet = constraint.nodeSets.get(inNode)
if (!nodeSet) {
nodeSet = new NodeSet(rdfListToArray(context.$shapes.node(inNode)))
constraint.nodeSets.set(inNode, nodeSet)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a list of node sets? I would expect a constraint object to represent a single sh:in constraint

Suggested change
const inNode = constraint.getParameterValue(sh.in)
if (!constraint.nodeSets) {
constraint.nodeSets = new TermMap()
}
let nodeSet = constraint.nodeSets.get(inNode)
if (!nodeSet) {
nodeSet = new NodeSet(rdfListToArray(context.$shapes.node(inNode)))
constraint.nodeSets.set(inNode, nodeSet)
}
if (!constraint.nodeSet) {
const inNode = constraint.getParameterValue(sh.in)
constraint.nodeSet = new NodeSet(rdfListToArray(context.$shapes.node(inNode)))
constraint.nodeSet = new TermMap()
}
const { nodeSet } = constraint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my understanding is that all the shapes with a sh:in constraint are sharing the same instance

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. getParameterValue gets the sh:in from the shape pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

@giacomociti giacomociti merged commit 1bb0383 into master Apr 16, 2024
3 checks passed
@giacomociti giacomociti deleted the list-perf branch April 16, 2024 08:25
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

Successfully merging this pull request may close these issues.

None yet

2 participants