Skip to content

Commit d64d60a

Browse files
K-jun98wilkinsona
authored andcommitted
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 <alap_u@naver.com>
1 parent fe07ad8 commit d64d60a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/CorrelationIdFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private CorrelationIdFormatter(List<Part> parts) {
8585
* @return a formatted correlation id
8686
*/
8787
public String format(UnaryOperator<String> resolver) {
88-
StringBuilder result = new StringBuilder();
88+
StringBuilder result = new StringBuilder(this.blank.length());
8989
formatTo(resolver, result);
9090
return result.toString();
9191
}

0 commit comments

Comments
 (0)