private void optimizeForStep(final TraversalParent step, final Traversal.Admin<?, ?> traversal, final Step singleStep) {
        if (singleStep instanceof PropertiesStep) {
            final PropertiesStep ps = (PropertiesStep) singleStep;
            if (ps.getReturnType().equals(PropertyType.VALUE) && ps.getPropertyKeys().length == 1) {
                step.replaceLocalChild(traversal, new ValueTraversal<>(ps.getPropertyKeys()[0]));
            }
        } else if (singleStep instanceof IdStep) {
            step.replaceLocalChild(traversal, new TokenTraversal<>(T.id));
        } else if (singleStep instanceof LabelStep) {
            step.replaceLocalChild(traversal, new TokenTraversal<>(T.label));
        } else if (singleStep instanceof PropertyKeyStep) {
            step.replaceLocalChild(traversal, new TokenTraversal<>(T.key));
        } else if (singleStep instanceof PropertyValueStep) {
            step.replaceLocalChild(traversal, new TokenTraversal<>(T.value));
        } else if (singleStep instanceof IdentityStep) {
            step.replaceLocalChild(traversal, new IdentityTraversal<>());
        }
    }
This strategy looks for standard traversals in by-modulators and replaces them with more optimized traversals
(e.g. {@code TokenTraversal}) if possible.
<p/>

@author Daniel Kuppitz (http://gremlin.guru)
@author Stephen Mallette (http://stephen.genoprime.com)
@example <pre>
__.path().by(id())                        // is replaced by __.path().by(id)
__.dedup().by(label())                    // is replaced by __.dedup().by(label)
__.order().by(values("name"))             // is replaced by __.order().by("name")
__.group().by().by(values("name").fold()) // is replaced by __.group().by("name")
</pre>
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/ByModulatorOptimizationStrategy.java