Uploaded image for project: 'TinkerPop'
  1. TinkerPop
  2. TINKERPOP-1471

IncidentToAdjacentStrategy use hidden marker to avoid repeated recursion.

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.2.2
    • Fix Version/s: 3.2.4
    • Component/s: process
    • Labels:
      None

      Description

      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.

        if (TraversalHelper.hasStepOfAssignableClassRecursively(INVALIDATING_STEP_CLASSES, TraversalHelper.getRootTraversal(traversal)))
                  return;
      

      Instead, it would be smart to do this and then, you don't need to recurse from the root traversal over and over again.

          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.
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                okram Marko A. Rodriguez
                Reporter:
                okram Marko A. Rodriguez
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: