From d64d60a8f056bcea0cbd56a87a1630610affb49a Mon Sep 17 00:00:00 2001 From: gobeomjun Date: Fri, 14 Nov 2025 02:04:01 +0900 Subject: [PATCH] Optimize StringBuilder initialization in CorrelationIdFormatter Initialize StringBuilder with the expected capacity (this.blank.length()) to avoid unnecessary resizing and array copying during string construction. The blank field already contains the exact length needed for the formatted output, making it an ideal initial capacity. This improves performance for correlation ID formatting, which is frequently called during logging operations. See gh-48125 Signed-off-by: gobeomjun --- .../springframework/boot/logging/CorrelationIdFormatter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/CorrelationIdFormatter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/CorrelationIdFormatter.java index cd30a1eaf29..67873e798a8 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/CorrelationIdFormatter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/CorrelationIdFormatter.java @@ -85,7 +85,7 @@ public final class CorrelationIdFormatter { * @return a formatted correlation id */ public String format(UnaryOperator resolver) { - StringBuilder result = new StringBuilder(); + StringBuilder result = new StringBuilder(this.blank.length()); formatTo(resolver, result); return result.toString(); }