@Override
    public void apply(final Traversal.Admin<?, ?> traversal) {
        // ByModulating steps should also be TraversalParent in most cases - if they aren't this strategy
        // probably doesn't need to fuss with them
        TraversalHelper.getStepsOfAssignableClass(ByModulating.class, traversal).stream().
                filter(bm -> bm instanceof TraversalParent).forEach(bm -> {
            final TraversalParent parentStep = (TraversalParent) bm;
            for (Traversal.Admin child : parentStep.getLocalChildren()) {
                // just outright skip the PropertyMapStep.propertyTraversal - it is only set by SubgraphStrategy and
                // for this case it doesn't make sense to force that traversal to be productive. if it is forced then
                // PropertyMap actually gets a null Property object if the traversal is not productive and that
                // causes an NPE. It doesn't make sense to catch the NPE there really as the code wants an empty
                // Iterator<Property> rather than a productive null. Actually, the propertyTraversal isn't even a
                // by() provided Traversal, so it really doesn't make sense for this strategy to touch it. Another
                // sort of example where strategies shouldn't have to know so much about one another. also, another
                // scenario where ProductiveByStrategy isn't so good. the default behavior without this strategy
                // works so much more nicely
                if (parentStep instanceof PropertyMapStep) {
                    final Traversal.Admin propertyTraversal = ((PropertyMapStep) parentStep).getPropertyTraversal();
                    if (propertyTraversal != null && propertyTraversal.equals(child))
                        continue;
                }

                if (child instanceof ValueTraversal &&  !containsValidByPass((ValueTraversal) child) &&
                        hasKeyNotKnownAsProductive((ValueTraversal) child)) {
                    wrapValueTraversalInCoalesce(parentStep, child);
                } else if (!(child.getEndStep() instanceof ReducingBarrierStep)) {
                    // ending reducing barrier will always return something so seems safe to not bother wrapping
                    // that up in coalesce().
                    final Traversal.Admin extractedChildTraversal = new DefaultGraphTraversal<>();
                    TraversalHelper.removeToTraversal(child.getStartStep(), EmptyStep.instance(), extractedChildTraversal);
                    child.addStep(new CoalesceStep(child, extractedChildTraversal, nullTraversal));

                    // replace so that internally the parent step gets to re-initialize the child as it may need to.
                    try {
                        parentStep.replaceLocalChild(child, child);
                    } catch (IllegalStateException ignored) {
                        // ignore situations where the parent traversal doesn't support replacement. in those cases
                        // we simply retain whatever the original behavior was even if it is inconsistent
                    }
                }
            }
        });
    }
Gets the standard configuration of this strategy that will apply it for all conditions. It is this version of
the strategy that is added as standard. Note that it may be helpful to configure a custom instance using the
{@link #build()} method in cases where there is certainty that a {@code by()} will be productive as it will
reduce the complexity of the traversal and perhaps improve the execution of other optimizations.
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/ProductiveByStrategy.java