Skip to content

Commit

Permalink
[FLINK-19286][runtime] Improve region sorting performance
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuzhurk committed Sep 23, 2020
1 parent f89c137 commit 247e452
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
Expand Down Expand Up @@ -81,6 +82,14 @@ static List<SchedulingPipelinedRegion> sortPipelinedRegionsInTopologicalOrder(
final SchedulingTopology topology,
final Set<SchedulingPipelinedRegion> regions) {

// Avoid the O(V) (V is the number of vertices in the topology) sorting
// complexity if the given set of regions is small enough
if (regions.size() == 0) {
return Collections.emptyList();
} else if (regions.size() == 1) {
return Collections.singletonList(regions.iterator().next());
}

return IterableUtils.toStream(topology.getVertices())
.map(SchedulingExecutionVertex::getId)
.map(topology::getPipelinedRegionOfVertex)
Expand Down

0 comments on commit 247e452

Please sign in to comment.