mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
#9255 Speedup pipeline compilation by making IfVertex more efficient
Fixes #9278
This commit is contained in:
parent
ba51a0d6b1
commit
798313f193
3 changed files with 9 additions and 15 deletions
|
@ -348,7 +348,7 @@ public final class CompiledPipeline {
|
||||||
);
|
);
|
||||||
// It is important that we double check that we are actually dealing with the
|
// It is important that we double check that we are actually dealing with the
|
||||||
// positive/left branch of the if condition
|
// positive/left branch of the if condition
|
||||||
if (ifvert.getOutgoingBooleanEdgesByType(true).stream()
|
if (ifvert.outgoingBooleanEdgesByType(true)
|
||||||
.anyMatch(edge -> Objects.equals(edge.getTo(), start))) {
|
.anyMatch(edge -> Objects.equals(edge.getTo(), start))) {
|
||||||
return ifDataset;
|
return ifDataset;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package org.logstash.config.ir.graph;
|
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.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
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.
|
* Created by andrewvc on 9/15/16.
|
||||||
|
@ -61,13 +60,8 @@ public class IfVertex extends Vertex {
|
||||||
return (e instanceof BooleanEdge);
|
return (e instanceof BooleanEdge);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<BooleanEdge> getOutgoingBooleanEdges() {
|
public Stream<BooleanEdge> outgoingBooleanEdgesByType(boolean edgeType) {
|
||||||
// Wish there was a way to do this as a java a cast without an operation
|
return outgoingEdges().map(e -> (BooleanEdge) e).filter(e -> e.getEdgeType() == edgeType);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The easiest readable version of this for a human.
|
// The easiest readable version of this for a human.
|
||||||
|
|
|
@ -53,8 +53,8 @@ public class IfVertexTest {
|
||||||
assertThat(ifV.getUnusedOutgoingEdgeFactories().isEmpty(), is(true));
|
assertThat(ifV.getUnusedOutgoingEdgeFactories().isEmpty(), is(true));
|
||||||
|
|
||||||
|
|
||||||
BooleanEdge trueEdge = ifV.getOutgoingBooleanEdgesByType(true).stream().findAny().get();
|
BooleanEdge trueEdge = ifV.outgoingBooleanEdgesByType(true).findAny().get();
|
||||||
BooleanEdge falseEdge = ifV.getOutgoingBooleanEdgesByType(false).stream().findAny().get();
|
BooleanEdge falseEdge = ifV.outgoingBooleanEdgesByType(false).findAny().get();
|
||||||
assertThat(trueEdge.getEdgeType(), is(true));
|
assertThat(trueEdge.getEdgeType(), is(true));
|
||||||
assertThat(falseEdge.getEdgeType(), is(false));
|
assertThat(falseEdge.getEdgeType(), is(false));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue