Marko A. Rodriguez created TINKERPOP-1471:
---------------------------------------------
Summary: IncidentToAdjacentStrategy use hidden marker to avoid
repeated recursion.
Key: TINKERPOP-1471
URL: https://issues.apache.org/jira/browse/TINKERPOP-1471
Project: TinkerPop
Issue Type: Improvement
Components: process
Affects Versions: 3.2.2
Reporter: Marko A. Rodriguez
Assignee: Daniel Kuppitz
TINKERPOP-1456 introduces the notion that "hidden labels" on steps will be
removed from the traversal prior to evaluation. This use of "hidden labels" was
necessary for {{SubgraphStrategy}} and it is not always possible to remove the
add "hidden labels" in {{SubgraphStrategy}} completely. Thus, prior to
evaluation, in hidden labels are removed.
This concept of "hidden labels" is useful for marking steps in a traversal so
that a strategy applied at a child gets information from the strategy applied
at a parent.
This can be used to make {{IncidentToAdjacentStrategy}} faster. In particular,
the following recursion is called repeatedly for each child.
{code}
if
(TraversalHelper.hasStepOfAssignableClassRecursively(INVALIDATING_STEP_CLASSES,
TraversalHelper.getRootTraversal(traversal)))
return;
{code}
Instead, it would be smart to do this and then, you don't need to recurse from
the root traversal over and over again.
{code}
private final void addMarkerToChildren(final Traversal.Admin<?, ?>
traversal) {
traversal.getStartStep().addLabel(MARKER);
for (final Step<?, ?> step : traversal.getSteps()) {
if (step instanceof TraversalParent) {
((TraversalParent)
step).getLocalChildren().forEach(this::addMarkerToChildren);
((TraversalParent)
step).getGlobalChildren().forEach(this::addMarkerToChildren);
}
}
}
public void apply(Traversal traversal) {
if(traversal.getParent() instanceof EmptyStep) {
boolean mark =
TraversalHelper.hasStepOfAssignableClassRecursively(INVALIDATING_STEP_CLASSES,
traversal)
if(mark) this.addMarkerToChildren(traversal)
}
// if the marker exists, don't optimize
if(traversal.getStartStep().getLabels().contains(MARKER)) {
traversal.getStartStep().removeLabel(MARKER);
return;
}
// else do the rest of the code.
}
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)