From 64b4aa6fdde6a65b8157578036374623a47c18c2 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Fri, 30 Aug 2024 17:59:11 -0700 Subject: [PATCH] Memoize toString() for MetricKey and MetricName (#32379) --- .../src/main/java/org/apache/beam/sdk/metrics/MetricKey.java | 4 +++- .../src/main/java/org/apache/beam/sdk/metrics/MetricName.java | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricKey.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricKey.java index c092db1e7a8c..81e995b39afd 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricKey.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricKey.java @@ -18,6 +18,7 @@ package org.apache.beam.sdk.metrics; import com.google.auto.value.AutoValue; +import com.google.auto.value.extension.memoized.Memoized; import java.io.Serializable; import org.checkerframework.checker.nullness.qual.Nullable; @@ -32,7 +33,8 @@ public abstract class MetricKey implements Serializable { public abstract MetricName metricName(); @Override - public final String toString() { + @Memoized + public String toString() { return stepName() + ":" + metricName(); } diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricName.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricName.java index f452ebeefc4c..31607d3330e0 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricName.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/MetricName.java @@ -20,6 +20,7 @@ import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument; import com.google.auto.value.AutoValue; +import com.google.auto.value.extension.memoized.Memoized; import java.io.Serializable; import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Strings; @@ -39,6 +40,7 @@ public abstract class MetricName implements Serializable { public abstract String getName(); @Override + @Memoized public String toString() { return getNamespace() + ":" + getName(); }