[ 
https://issues.apache.org/jira/browse/LOG4J2-1329?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15216024#comment-15216024
 ] 

Remko Popma commented on LOG4J2-1329:
-------------------------------------

I see. I need to think about this a bit more. There is some trade-off here 
between making things gc-free and avoiding copying. 

I'm not sure that it is a good idea to put the onus on the Message to provide a 
CharSequence (to avoid copying): it brings back the problem of how Messages can 
achieve that in a gc-free manner.

This problem was solved by LOG4J2-1274 (the StringBuilderFormattable.formatTo 
design), but if you want to bypass that solution I think you should provide an 
alternative solution for the original problem.

Also, I can only find 3 message implementations that would benefit from this 
(because they already contain the fully formatted message text):
* SimpleMessage
* ReusableSimpleMessage
* RingBufferLogEvent (when initialized with a ReusableMessage)

All the other Message implementations postpone the formatting until as late as 
possible, which is the layout stage. So there is no superfluous copying for 
messages other than the above three, which makes me wonder how much of a 
problem the copying really is.

> API change: let Message.getFormattedMessage() return CharSequence instead of 
> String
> -----------------------------------------------------------------------------------
>
>                 Key: LOG4J2-1329
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1329
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: API
>    Affects Versions: 2.5
>            Reporter: Remko Popma
>
> I propose that we change {{Message.getFormattedMessage()}} to return a 
> {{CharSequence}} instead of a String.
> I believe this change would be backwards compatible (all Message 
> implementations that return a String will work as is), and it opens the way
> for zero-GC Message implementations to return a cached StringBuilder as 
> Mikael [suggested on the log4j-dev mailing 
> list|http://mail-archives.apache.org/mod_mbox/logging-log4j-dev/201603.mbox/%3CCAAFrFhSs4EqjOERwHObKAZP4wjGWeiCET1nyE1FVndYdePk2yw%40mail.gmail.com%3E].



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to