Skip to content

Commit

Permalink
Reduce garbage from allocations in deprecation logger (#38780) (#39370)
Browse files Browse the repository at this point in the history
1. Setting length for formatWarning String to avoid AbstractStringBuilder.ensureCapacityInternal calls
2. Adding extra check for parameter array length == 0 to avoid unnecessarily creating StringBuilder in LoggerMessageFormat.format

Helps to narrow the performance gap in throughout for geonames benchmark (#37411) by 3%. For more details: #37530 (comment) 

Relates to #37530
Relates to #37411
Relates to #35754
  • Loading branch information
ebadyano authored Feb 25, 2019
1 parent 5c7dd6f commit 1ed3407
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ public Void run() {
* @return a warning value formatted according to RFC 7234
*/
public static String formatWarning(final String s) {
return WARNING_PREFIX + " " + "\"" + escapeAndEncode(s) + "\"";
// Assume that the common scenario won't have a string to escape and encode.
int length = WARNING_PREFIX.length() + s.length() + 3;
final StringBuilder sb = new StringBuilder(length);
sb.append(WARNING_PREFIX).append(" \"").append(escapeAndEncode(s)).append("\"");
return sb.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static String format(final String prefix, final String messagePattern, fi
if (messagePattern == null) {
return null;
}
if (argArray == null) {
if (argArray == null || argArray.length == 0) {
if (prefix == null) {
return messagePattern;
} else {
Expand Down

0 comments on commit 1ed3407

Please sign in to comment.