Avoid redundant copies in TaskStats#summarize
@@ -24,7 +24,6 @@ import javax.annotation.Nullable;
import java.util.List;
import java.util.Set;
-import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
@@ -570,9 +569,17 @@ public class TaskStats
physicalWrittenDataSizeInBytes,
fullGcCount,
fullGcTimeInMillis,
- pipelines.stream()
- .map(PipelineStats::summarize)
- .collect(Collectors.toList()),
+ summarizePipelineStats(pipelines),
runtimeStats);
}
+
+ private static List<PipelineStats> summarizePipelineStats(List<PipelineStats> pipelines)
+ {
+ // Use an exact size ImmutableList builder to avoid a redundant copy in the TaskStats constructor
+ ImmutableList.Builder<PipelineStats> results = ImmutableList.builderWithExpectedSize(pipelines.size());
+ for (PipelineStats pipeline : pipelines) {
+ results.add(pipeline.summarize());
+ }
+ return results.build();
+ }
}
