-
Notifications
You must be signed in to change notification settings - Fork 12
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
Conversation
🦋 Changeset detectedLatest commit: 1329680 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
src/validators.js
Outdated
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) | ||
} |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct
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):