#9255 Speedup pipeline compilation by making IfVertex more efficient

Fixes #9278
This commit is contained in:
Armin 2018-03-22 17:34:39 +01:00 committed by Armin Braun
parent ba51a0d6b1
commit 798313f193
3 changed files with 9 additions and 15 deletions

View file

@ -348,7 +348,7 @@ public final class CompiledPipeline {
);
// It is important that we double check that we are actually dealing with the
// positive/left branch of the if condition
if (ifvert.getOutgoingBooleanEdgesByType(true).stream()
if (ifvert.outgoingBooleanEdgesByType(true)
.anyMatch(edge -> Objects.equals(edge.getTo(), start))) {
return ifDataset;
} else {

View file

@ -1,13 +1,12 @@
package org.logstash.config.ir.graph;
import org.logstash.config.ir.SourceComponent;
import org.logstash.common.SourceWithMetadata;
import org.logstash.config.ir.expression.BooleanExpression;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.logstash.common.SourceWithMetadata;
import org.logstash.config.ir.SourceComponent;
import org.logstash.config.ir.expression.BooleanExpression;
/**
* Created by andrewvc on 9/15/16.
@ -61,13 +60,8 @@ public class IfVertex extends Vertex {
return (e instanceof BooleanEdge);
}
public Collection<BooleanEdge> getOutgoingBooleanEdges() {
// Wish there was a way to do this as a java a cast without an operation
return getOutgoingEdges().stream().map(e -> (BooleanEdge) e).collect(Collectors.toList());
}
public Collection<BooleanEdge> getOutgoingBooleanEdgesByType(boolean edgeType) {
return getOutgoingBooleanEdges().stream().filter(e -> e.getEdgeType() == edgeType).collect(Collectors.toList());
public Stream<BooleanEdge> outgoingBooleanEdgesByType(boolean edgeType) {
return outgoingEdges().map(e -> (BooleanEdge) e).filter(e -> e.getEdgeType() == edgeType);
}
// The easiest readable version of this for a human.

View file

@ -53,8 +53,8 @@ public class IfVertexTest {
assertThat(ifV.getUnusedOutgoingEdgeFactories().isEmpty(), is(true));
BooleanEdge trueEdge = ifV.getOutgoingBooleanEdgesByType(true).stream().findAny().get();
BooleanEdge falseEdge = ifV.getOutgoingBooleanEdgesByType(false).stream().findAny().get();
BooleanEdge trueEdge = ifV.outgoingBooleanEdgesByType(true).findAny().get();
BooleanEdge falseEdge = ifV.outgoingBooleanEdgesByType(false).findAny().get();
assertThat(trueEdge.getEdgeType(), is(true));
assertThat(falseEdge.getEdgeType(), is(false));
}