private ExpressionNode optimizeReduceJoin(ExpressionNode node) {
        if ( ! (node instanceof TensorFunctionNode)) {
            return node;
        }
        TensorFunction<Reference> function = ((TensorFunctionNode) node).function();
        if ( ! (function instanceof Reduce)) {
            return node;
        }
        List<ExpressionNode> children = ((TensorFunctionNode) node).children();
        if (children.size() != 1) {
            return node;
        }
        ExpressionNode child = children.get(0);
        if ( ! (child instanceof TensorFunctionNode)) {
            return node;
        }
        TensorFunction<Reference> argument = ((TensorFunctionNode) child).function();
        if (argument instanceof Join) {
            report.incMetric("Replaced reduce->join", 1);
            return new TensorFunctionNode(new ReduceJoin<>((Reduce<Reference>)function, (Join<Reference>)argument));
        }
        return node;
    }
Recognized a reduce followed by a join. In many cases, chunking these
two operations together is significantly more efficient than evaluating
each on its own, avoiding the cost of a temporary tensor.

Note that this does not guarantee that the optimization is performed.
The ReduceJoin class determines whether or not the arguments are
compatible with the optimization.
searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/tensoroptimization/TensorOptimizer.java