carterkozak commented on a change in pull request #797:
URL: https://github.com/apache/logging-log4j2/pull/797#discussion_r827098067



##########
File path: 
log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageResolver.java
##########
@@ -134,7 +134,10 @@ private static void resolveString(
             jsonWriter.writeObjectStart();
             jsonWriter.writeObjectKey(fallbackKey);
         }
-        if (message instanceof StringBuilderFormattable) {
+        if (message instanceof CharSequence) {

Review comment:
       Is this an optimization for SimpleMessage? I wonder if there's something 
we can do better in `jsonWriter.writeString(StringBuilderFormattable)`? in the 
SimpleMessage/ReusableSimpleMessage case, I suspect we would do better using 
`getFormattedMessage()` as `StringBuilder.append(String)` is faster than 
iterating over a charsequence. Note that this would allocate in the case that 
the message value is a non-string charsequence.
   
   StringBuilderFormattable handling writes from the original message to an 
intermediate StringBuilder, which is escaped into the final StringBuilder. I 
think we could probably optimize this process, for instance I think we always 
call `quoteString(formattableBuffer, 0, length);` which uses 
`StringBuilder.append(cs,start,end)` rather than `StringBuilder.append(cs)` -- 
unfortunately only the latter appears to be special-cased for 
AbstractStringBuilder.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to