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

Remko Popma commented on LOG4J2-1282:
-------------------------------------

Some initial thoughts: one way to address this issue is to use a different data 
structure than provided by the java util collections framework.

I noticed that ThreadContextMap is passed downstream as a Map<String,String> 
but only a small subset of the Map API is used by the downstream client code:
* isEmpty()
* looping over the key-value pairs (currently via entrySet() or keySet()) 
* containsKey(String key)
* get(String key)
* toString()

Both the configuration properties map and the ThreadContext map are likely 
small (less than 100 entries). We could create a custom gc-free array-based 
implementation. For the rare cases where client code calls get() or 
containsKey() without looping over the map contents, a linear scan over the 
array may perform well enough.


> Make RingBufferLogEvent::mergePropertiesIntoContextMap allocation-free if 
> possible
> ----------------------------------------------------------------------------------
>
>                 Key: LOG4J2-1282
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1282
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.5
>            Reporter: Remko Popma
>
> RingBufferLogEvent::mergePropertiesIntoContextMap is called in the background 
> (consumer) thread for each event.
> If configuration properties are specified it allocates the following 
> temporary objects:
> * make mutable copy of the ThreadContext map
> * iterator over configuration properties map
> * for config values containing ${} placeholders, call 
> {{StrSubstitutor.replace}} (which creates multiple temporary objects)
> (If configuration properties are not specified, no temporary objects are 
> allocated.)



--
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