ppkarwasz commented on PR #2593:
URL: https://github.com/apache/logging-log4j2/pull/2593#issuecomment-2128057825

   > @ppkarwasz In general I agree with this proposal. If 
StringArrayThreadContextMap performs the best the I would be in favor of making 
it the default implementation. I am not sure how you are using the term 
"garbage free" here. Our documentation talks about "garbage free logging" and 
that is what the unit tests check for - no garbage being created while logging. 
Garbage created outside of logging is considered to be OK.
   
   The `GarbageFreeSortedArrayStringMap` satisfies a stronger definition of 
garbage-free. Code like this one:
   
   ```java
   try {
       ThreadContext.put("key1", "value1");
       ThreadContext.put("key2", "value2");
       logger.info("Hello {}!", "ThreadContext");
   } finally {
       ThreadContext.remove("key1");
       ThreadContext.remove("key2");
   }
   ```
   
   generate no garbage, whereas:
   
   ```java
   ScopedContext.where("key1", "value1")
           .where("key2", "value2")
           .run(() -> logger.info("Hello {}!", "ScopedContext"));
   ```
   
   creates several temporary objects.


-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to