Details
-
Improvement
-
Resolution: Unresolved
-
Major
-
None
-
None
-
None
Description
When setting or duplicating the MDC context map, a synchronized map is used. This incurs the overhead of locking when putting key-value pairs into the map. This overhead can be avoided, because the map is method-local and only a single thread can access it a single time.
Delay wrapping the map in a synchronizedMap until before it leaves the scope of the method.
You can find the proposed changes in https://github.com/qos-ch/logback/pull/462
I have not performed any benchmarks and would appreciate if somebody could write some. Maybe the JVM is already clever enough to detect this useless synchronization and elides the lock?