From e81f3d715cb7d6f52f4406ad87981cece7f942d8 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Mon, 11 Dec 2023 00:08:17 +0900 Subject: [PATCH] Use cache for base time unit strings Closes gh-4352 --- .../java/io/micrometer/core/instrument/MeterRegistry.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/MeterRegistry.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/MeterRegistry.java index d016131cca..0bb5e289b7 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/MeterRegistry.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/MeterRegistry.java @@ -279,8 +279,12 @@ protected String getConventionName(Meter.Id id) { */ protected abstract DistributionStatisticConfig defaultHistogramConfig(); + private final EnumMap baseTimeUnitStringCache = new EnumMap<>(TimeUnit.class); + private String getBaseTimeUnitStr() { - return getBaseTimeUnit().toString().toLowerCase(); + TimeUnit baseTimeUnit = getBaseTimeUnit(); + return this.baseTimeUnitStringCache.computeIfAbsent(baseTimeUnit, + (timeUnit) -> timeUnit.toString().toLowerCase()); } /**