Skip to content

Commit

Permalink
Avoid redundant copies in TaskStats#summarize
Browse files Browse the repository at this point in the history
  • Loading branch information
pettyjamesm authored and martint committed Nov 12, 2021
1 parent e703ddd commit f54f076
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions core/trino-main/src/main/java/io/trino/operator/TaskStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

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;
Expand Down Expand Up @@ -598,8 +597,16 @@ public TaskStats summarizeFinal()
physicalWrittenDataSize,
fullGcCount,
fullGcTime,
pipelines.stream()
.map(PipelineStats::summarize)
.collect(Collectors.toList()));
summarizePipelineStats(pipelines));
}

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();
}
}

0 comments on commit f54f076

Please sign in to comment.