You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/09/24 13:56:05 UTC

[1/2] logging-log4j2 git commit: LOG4J2-1611 performance optimization when merging logger properties with context data: using JdkMapAdapterStringMap is much faster than building a SortedArrayStringMap from an unsorted Map; removed method

Repository: logging-log4j2
Updated Branches:
  refs/heads/master c05f75b43 -> 8353c6d0c


LOG4J2-1611 performance optimization when merging logger properties with context data: using JdkMapAdapterStringMap is much faster than building a SortedArrayStringMap from an unsorted Map<String, String>; removed method copyThreadContextMap() - became unused


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/580fbb4e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/580fbb4e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/580fbb4e

Branch: refs/heads/master
Commit: 580fbb4e9bd379d726328e10753cf10095acb1d2
Parents: c05f75b
Author: rpopma <rp...@apache.org>
Authored: Sat Sep 24 22:54:29 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Sep 24 22:54:29 2016 +0900

----------------------------------------------------------------------
 .../core/impl/ThreadContextDataInjector.java    | 28 +++++++-------------
 1 file changed, 10 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/580fbb4e/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
index 832a8cb..810eaf8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
@@ -16,6 +16,7 @@
  */
 package org.apache.logging.log4j.core.impl;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -77,13 +78,18 @@ public class ThreadContextDataInjector  {
                 // this will replace the LogEvent's context data with the returned instance
                 return copy.isEmpty() ? EMPTY_STRING_MAP : new JdkMapAdapterStringMap(copy);
             }
-            // However, if the list of Properties is non-empty we need to combine the properties and the ThreadContext
+            // If the list of Properties is non-empty we need to combine the properties and the ThreadContext
             // data. Note that we cannot reuse the specified StringMap: some Loggers may have properties defined
             // and others not, so the LogEvent's context data may have been replaced with an immutable copy from
             // the ThreadContext - this will throw an UnsupportedOperationException if we try to modify it.
-            final StringMap result = ContextDataFactory.createContextData(props.size() + copy.size());
-            copyProperties(props, result);
-            copyThreadContextMap(copy, result);
+            final StringMap result = new JdkMapAdapterStringMap(new HashMap<>(copy));
+            for (int i = 0; i < props.size(); i++) {
+                final Property prop = props.get(i);
+                if (!copy.containsKey(prop.getName())) {
+                    result.putValue(prop.getName(), prop.getValue());
+                }
+            }
+            result.freeze();
             return result;
         }
 
@@ -95,20 +101,6 @@ public class ThreadContextDataInjector  {
             }
             return map.isEmpty() ? EMPTY_STRING_MAP : new JdkMapAdapterStringMap(map.getImmutableMapOrNull());
         }
-
-        /**
-         * Copies key-value pairs from the specified map into the specified {@code StringMap}.
-         *
-         * @param map map with key-value pairs, may be {@code null}
-         * @param result the {@code StringMap} object to add the key-values to. Must be non-{@code null}.
-         */
-        private static void copyThreadContextMap(final Map<String, String> map, final StringMap result) {
-            if (map != null) {
-                for (final Map.Entry<String, String> entry : map.entrySet()) {
-                    result.putValue(entry.getKey(), entry.getValue());
-                }
-            }
-        }
     }
 
     /**


[2/2] logging-log4j2 git commit: LOG4J2-1611 LOG4J2-1010 LOG4J2-1447 update benchmark: put & remove guarantees mutation on every call (just put same key only mutates once)

Posted by rp...@apache.org.
LOG4J2-1611 LOG4J2-1010 LOG4J2-1447 update benchmark: put & remove guarantees mutation on every call (just put same key only mutates once)


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/8353c6d0
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/8353c6d0
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/8353c6d0

Branch: refs/heads/master
Commit: 8353c6d0c86cbeddf406325094b90f91775daf2c
Parents: 580fbb4
Author: rpopma <rp...@apache.org>
Authored: Sat Sep 24 22:55:59 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Sep 24 22:55:59 2016 +0900

----------------------------------------------------------------------
 .../org/apache/logging/log4j/perf/jmh/ThreadContextBenchmark.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8353c6d0/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextBenchmark.java
index 2f61369..ed30f58 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextBenchmark.java
@@ -156,8 +156,9 @@ public class ThreadContextBenchmark {
     }
 
     @Benchmark
-    public void put() {
+    public void putAndRemove() {
         ThreadContext.put("someKey", "someValue");
+        ThreadContext.remove("someKey");
     }
 
     @Benchmark