From 8b18ba8087a988212a495aabb178e4857c7de67c 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. Signed-off-by: gobeomjun --- .../springframework/boot/logging/CorrelationIdFormatter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/spring-boot/src/main/java/org/springframework/boot/logging/CorrelationIdFormatter.java b/core/spring-boot/src/main/java/org/springframework/boot/logging/CorrelationIdFormatter.java index d7b7a7ea50e7..e1854e4cd8c7 100644 --- a/core/spring-boot/src/main/java/org/springframework/boot/logging/CorrelationIdFormatter.java +++ b/core/spring-boot/src/main/java/org/springframework/boot/logging/CorrelationIdFormatter.java @@ -87,7 +87,7 @@ private CorrelationIdFormatter(List parts) { * @return a formatted correlation id */ public String format(UnaryOperator<@Nullable String> resolver) { - StringBuilder result = new StringBuilder(); + StringBuilder result = new StringBuilder(this.blank.length()); formatTo(resolver, result); return result.toString(); }