-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix regression in JdkMapAdapterStringMap
performance
#2256
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for promptly handling this. I guess this warrants a quick 2.23.0
release.
Changes LGTM. But I am not feeling confident enough to say we addressed the problem. I don't see a test triggering the code path users reported. Can you add such a test, please? Maybe we can craft/mock a custom map throwing an [unexpected] exception on replace()
and verify that replace()
is not called?
...j-core-test/src/test/java/org/apache/logging/log4j/core/impl/JdkMapAdapterStringMapTest.java
Outdated
Show resolved
Hide resolved
...j-core-test/src/test/java/org/apache/logging/log4j/core/impl/JdkMapAdapterStringMapTest.java
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/JdkMapAdapterStringMap.java
Outdated
Show resolved
Hide resolved
f83d192
to
fbdef6c
Compare
return map; | ||
return new HashMap<>(map); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is required by the toMap
contract, which requires a "mutable snapshot of the underlying data".
This seems strange to me. Why wouldn't you create an ImmutableJdkMapAdapterStringMap that extends JdkMapAdapterStringMap (or vice versa) instead of using a boolean parameter? It seems like it would be cleaner. |
The original problem in #2098 was that a user implemented I tried auto-detecting the problem which caused the performance issue we are facing today. By adding a new constructor I want to give users clear directions that:
I can create an |
We introduce a new constructor for `JdkMapAdapterStringMap` to prevent the performance penalty of an exception if the map is immutable.
f9667f4
to
75ed23a
Compare
I think that an entire |
We introduce a new constructor for
JdkMapAdapterStringMap
to prevent the performance penalty of an exception if the map is immutable. The regression was introduced in #2101.Closes #2238.