Github user dkuppitz commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/445#discussion_r81550568 --- Diff: gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategy.java --- @@ -72,97 +75,163 @@ public void apply(final Traversal.Admin<?, ?> traversal) { boolean changed = true; // recursively walk child traversals trying to inline them into the current traversal line. while (changed) { changed = false; - // filter(x.y) --> x.y - for (final TraversalFilterStep<?> step : TraversalHelper.getStepsOfClass(TraversalFilterStep.class, traversal)) { - final Traversal.Admin<?, ?> childTraversal = step.getLocalChildren().get(0); - if (TraversalHelper.hasAllStepsOfClass(childTraversal, FilterStep.class) && - !TraversalHelper.hasStepOfClass(childTraversal, - DropStep.class, - RangeGlobalStep.class, - DedupGlobalStep.class, - LambdaHolder.class)) { + for (final FilterStep<?> step : TraversalHelper.getStepsOfAssignableClass(FilterStep.class, traversal)) { --- End diff -- Complex traversal could waste a few CPU cycles in this method. Here's an optimized version: ``` @Override public void apply(final Traversal.Admin<?, ?> traversal) { boolean changed = true; // recursively walk child traversals trying to inline them into the current traversal line. while (changed) { changed = false; final Iterator<FilterStep> filterStepIterator = TraversalHelper.getStepsOfAssignableClass(FilterStep.class, traversal).iterator(); while (!changed && filterStepIterator.hasNext()) { final FilterStep<?> step = filterStepIterator.next(); changed = step instanceof HasStep && InlineFilterStrategy.processHasStep((HasStep) step, traversal) || step instanceof TraversalFilterStep && InlineFilterStrategy.processTraversalFilterStep((TraversalFilterStep) step, traversal) || step instanceof OrStep && InlineFilterStrategy.processOrStep((OrStep) step, traversal) || step instanceof AndStep && InlineFilterStrategy.processAndStep((AndStep) step, traversal); } if (!changed && traversal.getParent() instanceof EmptyStep) { final Iterator<MatchStep> matchStepIterator = TraversalHelper.getStepsOfClass(MatchStep.class, traversal).iterator(); while (!changed && matchStepIterator.hasNext()) { if (InlineFilterStrategy.processMatchStep(matchStepIterator.next(), traversal)) changed = true; } } } } ```
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---