-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Optimize DefaultThreadContextMap.getCopy() performance #3939
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
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.
@jengebr, @anuragdy, thanks so much for the report and the fix. I see that you provided a benchmark in #3935. Curious: Have you checked the existing log4j-perf-test
benchmarks on thread context map? Are you able to reproduce the improvement figures using one of the benchmarks there? If so, which one(s)? If not, would you mind updating existing MDC benchmarks accordingly, please?
log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
Outdated
Show resolved
Hide resolved
log4j-api-test/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
Outdated
Show resolved
Hide resolved
log4j-api-test/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
Outdated
Show resolved
Hide resolved
log4j-api-test/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
Outdated
Show resolved
Hide resolved
log4j-api-test/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
Outdated
Show resolved
Hide resolved
log4j-api-test/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
Outdated
Show resolved
Hide resolved
@anuragdy, build is failing, would you mind fixing it, please? See the Log4j Development Guide for details. |
Head branch was pushed to by a user without write access
- Fix incorrect indentation in the for loop that was causing compilation failures - Remove redundant performance figures comment as intended in the original commit - Fix duplicate JavaDoc comment that was causing subsequent compilation failures This resolves the GitHub Actions CI build failures in PR apache#3939.
@anuragdy, please sign your commits. |
- Fix incorrect indentation in the for loop that was causing compilation failures - Remove redundant performance figures comment as intended in the original commit - Fix duplicate JavaDoc comment that was causing subsequent compilation failures This resolves the GitHub Actions CI build failures in PR apache#3939.
c81a658
to
4b981eb
Compare
Thanks for the guidelines, updated. The build workflow is succeeding on the fork now.
Updated the commits. |
This PR optimizes the
DefaultThreadContextMap.getCopy()
method to address performance issues related to megamorphic calls in the HashMap constructor, providing 30-50% performance improvements for non-empty maps.The original implementation used
new HashMap<>(map)
which suffers from megamorphic call performance issues documented in:The HashMap constructor with a Map parameter requires (3 + 4n) virtual method calls that become megamorphic when used with different map types, leading to 24-136% performance degradation compared to manual iteration.
Closes #3935.