New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid a slow exception catch in JdkMapAdapterStringMap constructor #2238
Comments
Thank you for this report. Can you supply a PR to correct this? Looking at the code you are pointing at, there is another optimization possible: |
@ppkarwasz I'm sorry, i don't really see the optimzation you saw with |
After looking better at the code the native storage of The: final ReadOnlyThreadContextMap map = ThreadContext.getThreadContextMap();
if (map instanceof ReadOnlyStringMap) {
return (ReadOnlyStringMap) map;
} is also wrong (a final ReadOnlyThreadContextMap map = ThreadContext.getThreadContextMap();
if (map != null) {
return map.getReadOnlyContextData();
} |
Can you check if the latest snapshot in the Maven repo |
@ppkarwasz Thank you. |
Discussed in #2235
Originally posted by jdgenerix January 24, 2024
The
org.apache.logging.log4j.core.impl.JdkMapAdapterStringMap
constructor is called fromorg.apache.logging.log4j.core.impl.ThreadContextDataInjector
with an UnmodiableMap (copy
) and the constructor is trying to modify and catch an exception to detect if this is an immutable Map.This code is triggered a lot of time and could be more efficient.
Adding a package protected constructor which take the immutable boolean flag as an argument and using it from
ThreadContextDataInjector
would avoid this slow try catch.The text was updated successfully, but these errors were encountered: