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

Remko Popma commented on LOG4J2-1271:
-------------------------------------

I see your point. The thing is, why are we currently doing so much work taking 
a snapshot of the parameters?

I assume it is to ensure that the {{getFormattedMessage}} method works when 
called from a different thread or when called after the message was 
serialized/deserialized.

Taking parameter snapshots has _significant_ overhead. I suspect it is even 
more than formatting the message. And then when getFormattedMessage() is called 
we need to do even more work... This doesn't make sense to me.

My take is this: if we are going to spend CPU cycles anyway (as you said, 
necessary to support async logging), I would rather spend them doing something 
that is likely to be necessary at some point (formatting the message). 

Once we have formatted the message, doesn't it then become unnecessary to take 
parameter snapshots?


> ParameterizedMessage optimization
> ---------------------------------
>
>                 Key: LOG4J2-1271
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1271
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: API
>    Affects Versions: 2.5
>            Reporter: Remko Popma
>            Assignee: Remko Popma
>
> ParameterizedMessage creates unnecessary objects and does other unnecessary 
> work in its constructor.
> On the other hand, it does not create the full formatted string it will 
> eventually need to return from {{getFormattedMessage()}}.
> I propose the following changes:
> * Don't call {{argumentsToStrings}} in the constructor. Converting the 
> parameter Object[] array to a String[] array should only be done when 
> necessary: when this ParameterizedMessage is serialized.
> * Don't copy the parameter Object[] array to a new array. Instead clone the 
> array when the {{getParameters()}} method is called.
> * In the constructor, build the fully formatted message. This combines the 
> work done by {{formatStringArgs(String, String[])}} and 
> {{argumentsToStrings(Object[])}} and avoids the issue mentioned in LOG4J2-763.



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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to