From 901fbfe7303c19a838872d7055b64d6332c2694f Mon Sep 17 00:00:00 2001 From: Ignacio Vera Date: Thu, 7 Nov 2024 15:15:38 +0100 Subject: [PATCH] Reuse metric names in TopMetricsAggregator (#116296) This commit shares a unique instance between all InternalTopMetrics instances. --- .../xpack/analytics/topmetrics/TopMetricsAggregator.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java index 3337b6d239413..69b6e311e23ee 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java @@ -40,11 +40,9 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; -import static java.util.stream.Collectors.toList; import static org.elasticsearch.xpack.analytics.topmetrics.TopMetricsAggregationBuilder.REGISTRY_KEY; /** @@ -148,9 +146,14 @@ public void doClose() { static class Metrics implements BucketedSort.ExtraData, Releasable { private final MetricValues[] values; + private final List names; Metrics(MetricValues[] values) { this.values = values; + names = new ArrayList<>(values.length); + for (MetricValues value : values) { + names.add(value.name); + } } boolean needsScores() { @@ -182,7 +185,7 @@ BucketedSort.ResultBuilder resultBuilder(DocValueF } List names() { - return Arrays.stream(values).map(v -> v.name).collect(toList()); + return names; } @Override