magicwerk opened a new pull request, #3645:
URL: https://github.com/apache/logging-log4j2/pull/3645

   It is one of the design goals of Log4j "to deliver excelling performance 
without almost any burden on the Java garbage collector."
   
   However this is currently not true for primitive arrays, here Log4j 
allocates unneeded temporary strings if a primitive array is logged as 
parameter.
   
   Current implementation:
   Method ParameterFormatter.appendArray() delegats to 
java.util.Arrays.toString() which then allocates a new StringBuilder to return 
a String which is then added to the existing StringBuilder.
   
   Improved implementation:
   For all primitive types, a method like ParameterFormatter.appendArray(int[], 
StringBuilder) has been added which is called by 
ParameterFormatter.appendArray() and avoids the unnecessary object creation.
   
   A JHM benchmark shows that this changes increases performance and reduces 
memory consumption to zero:
   
   ```
   Benchmark                                      Mode  Cnt         Score       
 Error   Units
   testParameterFormatterNew                     thrpt    5  10090997.276 � 
758239.856   ops/s
   testParameterFormatterNew:gc.alloc.rate       thrpt    5         0.001 �     
 0.001  MB/sec
   testParameterFormatterNew:gc.alloc.rate.norm  thrpt    5        ? 10??       
          B/op
   testParameterFormatterNew:gc.count            thrpt    5           ? 0       
        counts
   testParameterFormatterOld                     thrpt    5   8259447.275 � 
349015.042   ops/s
   testParameterFormatterOld:gc.alloc.rate       thrpt    5      1259.364 �     
54.827  MB/sec
   testParameterFormatterOld:gc.alloc.rate.norm  thrpt    5       160.000 �     
 0.001    B/op
   testParameterFormatterOld:gc.count            thrpt    5        11.000       
        counts
   testParameterFormatterOld:gc.time             thrpt    5        11.000       
            ms
   ```
   
   Tests have been added to ParameterFormatterTest
   


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