diff --git a/core/trino-main/src/main/java/io/trino/operator/aggregation/builder/InMemoryHashAggregationBuilder.java b/core/trino-main/src/main/java/io/trino/operator/aggregation/builder/InMemoryHashAggregationBuilder.java index 97fe7f2cc1394..8ea87ae6025d6 100644 --- a/core/trino-main/src/main/java/io/trino/operator/aggregation/builder/InMemoryHashAggregationBuilder.java +++ b/core/trino-main/src/main/java/io/trino/operator/aggregation/builder/InMemoryHashAggregationBuilder.java @@ -99,7 +99,7 @@ public InMemoryHashAggregationBuilder( UpdateMemory updateMemory) { if (hashChannel.isPresent()) { - this.groupByOutputTypes = ImmutableList.builder() + this.groupByOutputTypes = ImmutableList.builderWithExpectedSize(groupByTypes.size() + 1) .addAll(groupByTypes) .add(BIGINT) .build(); @@ -126,8 +126,8 @@ public InMemoryHashAggregationBuilder( this.updateMemory = requireNonNull(updateMemory, "updateMemory is null"); // wrapper each function with an aggregator - ImmutableList.Builder builder = ImmutableList.builder(); requireNonNull(aggregatorFactories, "aggregatorFactories is null"); + ImmutableList.Builder builder = ImmutableList.builderWithExpectedSize(aggregatorFactories.size()); for (int i = 0; i < aggregatorFactories.size(); i++) { AggregatorFactory accumulatorFactory = aggregatorFactories.get(i); if (unspillIntermediateChannelOffset.isPresent()) { @@ -333,7 +333,7 @@ public int nextInt() public static List toTypes(List groupByType, List factories, Optional hashChannel) { - ImmutableList.Builder types = ImmutableList.builder(); + ImmutableList.Builder types = ImmutableList.builderWithExpectedSize(groupByType.size() + (hashChannel.isPresent() ? 1 : 0) + factories.size()); types.addAll(groupByType); if (hashChannel.isPresent()) { types.add(BIGINT); diff --git a/core/trino-main/src/main/java/io/trino/operator/aggregation/builder/MergingHashAggregationBuilder.java b/core/trino-main/src/main/java/io/trino/operator/aggregation/builder/MergingHashAggregationBuilder.java index 0caf336bba261..a332e2a9c3bbb 100644 --- a/core/trino-main/src/main/java/io/trino/operator/aggregation/builder/MergingHashAggregationBuilder.java +++ b/core/trino-main/src/main/java/io/trino/operator/aggregation/builder/MergingHashAggregationBuilder.java @@ -63,7 +63,7 @@ public MergingHashAggregationBuilder( int overwriteIntermediateChannelOffset, FlatHashStrategyCompiler hashStrategyCompiler) { - ImmutableList.Builder groupByPartialChannels = ImmutableList.builder(); + ImmutableList.Builder groupByPartialChannels = ImmutableList.builderWithExpectedSize(groupByTypes.size()); for (int i = 0; i < groupByTypes.size(); i++) { groupByPartialChannels.add(i); }