You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "jengebr (via GitHub)" <gi...@apache.org> on 2024/02/23 15:56:00 UTC

[I] Performance improvements to DefaultThreadContextMap (logging-log4j2)

jengebr opened a new issue, #2319:
URL: https://github.com/apache/logging-log4j2/issues/2319

   `DefaultThreadContextMap` maintains non-blocking thread safety by guaranteeing immutability, and performing copy-and-modify operations when adding or removing.  The referenced pull request  improves performance while maintaining functionality by creating a custom data structure (`UnmodifiableArrayBackedMap`).  According to the attached JMH benchmark, it outperforms the current implementation in every way - except that search operations (get/containsKey) become linear-time rather than constant. This appears to be a good tradeoff, especially in the common cases when the map is small (< 15 entries).  I welcome discussion on this point.
   
   Details: `DefaultThreadContextMap` currently implements the copy-and-modify by allocating a new `HashMap` (with a padded array), iterating through the existing `HashMap` (reading null buckets, and chasing nested `Node`s), then inserting each element into the new `HashMap` (`Nod`e allocation, hash/equals calculations). The new implementation reduces copying to a single array allocation and a single call to `System.arrayCopy(`.
    
   The JMH benchmarks attached to this issue show that copying and adding one entry to the new map is 1.5x faster when the existing map is empty, and the delta increases steadily up to 5x faster when 75 items are already present.  Similarly, adding 5 entries at a time is 2x faster when the map is empty, and the delta climbs to 5x faster when the map contains 75 items.
   
   Separate profiling suggests a reduction in memory allocation MB/s around 20%, mostly by eliminating the `Node` instances.
   
   Other JMH highlights:
   1. Iteration across the `entrySet()` improves by 8x to 20x.
   2. `get()` times are faster with 0 or 1 items in the map, but slower after 5+ items are present.
   
   JMH benchmark class: 
   [MapSpeedBenchmark.java.txt](https://github.com/apache/logging-log4j2/files/14387210/MapSpeedBenchmark.java.txt)
   
   JMH benchmark results:  
   [MapSpeedBenchmark_results.txt](https://github.com/apache/logging-log4j2/files/14387226/MapSpeedBenchmark_results.txt)
   
   


-- 
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-unsubscribe@logging.apache.org.apache.org

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


Re: [I] Performance improvements to DefaultThreadContextMap (logging-log4j2)

Posted by "jengebr (via GitHub)" <gi...@apache.org>.
jengebr closed issue #2319: Performance improvements to DefaultThreadContextMap
URL: https://github.com/apache/logging-log4j2/issues/2319


-- 
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-unsubscribe@logging.apache.org

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


Re: [I] Performance improvements to DefaultThreadContextMap (logging-log4j2)

Posted by "jengebr (via GitHub)" <gi...@apache.org>.
jengebr commented on issue #2319:
URL: https://github.com/apache/logging-log4j2/issues/2319#issuecomment-1964225223

   Closing based on discussion on pull request.  No changes made.


-- 
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-unsubscribe@logging.apache.org

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


Re: [I] Performance improvements to DefaultThreadContextMap (logging-log4j2)

Posted by "jengebr (via GitHub)" <gi...@apache.org>.
jengebr commented on issue #2319:
URL: https://github.com/apache/logging-log4j2/issues/2319#issuecomment-1961593790

   Pull request: https://github.com/apache/logging-log4j2/pull/2321


-- 
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-unsubscribe@logging.apache.org

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