Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1683

(GC) Avoid allocating temporary objects in MapMessage

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.7
    • Fix Version/s: 2.8
    • Component/s: API
    • Labels:
      None

      Description

      Make MapMessage garbage-free.

      While working on LOG4J2-1677, I found that MapFilter itself can avoid allocating temporary objects, but when filtering a MapMessage, the message allocates a java/util/Collections$UnmodifiableMap:

      	at java.util.Collections.unmodifiableMap(Collections.java:1318)
      	at org.apache.logging.log4j.message.MapMessage.getData(MapMessage.java:102)
      	at org.apache.logging.log4j.core.filter.MapFilter.filter(MapFilter.java:70)
      

      Apart from the filtering, logging a MapMessage allocates a StringBuilder and an iterator over the TreeMap:

      	at java.lang.StringBuilder.<init>(StringBuilder.java:85)
      	at org.apache.logging.log4j.message.MapMessage.asString(MapMessage.java:189)
      	at org.apache.logging.log4j.message.MapMessage.asString(MapMessage.java:172)
      	at org.apache.logging.log4j.message.MapMessage.getFormattedMessage(MapMessage.java:229)
      	at org.apache.logging.log4j.core.async.RingBufferLogEvent.setMessage(RingBufferLogEvent.java:127)
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                remkop@yahoo.com Remko Popma
                Reporter:
                remkop@yahoo.com Remko Popma
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: