You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "anuragdy (via GitHub)" <gi...@apache.org> on 2025/09/25 04:45:58 UTC

[PR] Optimize DefaultThreadContextMap.getCopy() performance [logging-log4j2]

anuragdy opened a new pull request, #3938:
URL: https://github.com/apache/logging-log4j2/pull/3938

   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:
   - **GitHub Issue**: #3935  
   - **JDK Ticket**: [JDK-8368292](https://bugs.openjdk.org/browse/JDK-8368292)
   
   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.
   
   ## Checklist
   
   Before we can review and merge your changes, please go through the checklist below. If you're still working on some items, feel free to submit your pull request as a draft—our CI will help guide you through the remaining steps.
   
   ### ✅ Required checks
   
   - [x] **License**: I confirm that my changes are submitted under the [Apache License, Version 2.0](https://apache.org/licenses/LICENSE-2.0).
   - [x] **Commit signatures**: All commits are signed and verifiable. (See [GitHub Docs on Commit Signature Verification](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)).
   - [x] **Code formatting**: The code is formatted according to the project’s style guide.
     <details>
       <summary>How to check and fix formatting</summary>
   
       - To **check** formatting: `./mvnw spotless:check`
       - To **fix** formatting: `./mvnw spotless:apply`
   
       See [the build instructions](https://logging.apache.org/log4j/2.x/development.html#building) for details.
     </details>
   - [x] **Build & Test**: I verified that the project builds and all unit tests pass.
     <details>
       <summary>How to build the project</summary>
   
       Run: `./mvnw verify`
   
       See [the build instructions](https://logging.apache.org/log4j/2.x/development.html#building) for details.
     </details>
   
   ### 🧪 Tests (select one)
   
   - [x] I have added or updated tests to cover my changes.
   - [ ] No additional tests are needed for this change.
   
   ### 📝 Changelog (select one)
   
   - [x] I added a changelog entry in `src/changelog/.2.x.x`. (See [Changelog Entry File Guide](https://logging.apache.org/log4j/tools/log4j-changelog.html#changelog-entry-file)).
   - [ ] This is a trivial change and does not require a changelog entry.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Optimize DefaultThreadContextMap.getCopy() performance [logging-log4j2]

Posted by "anuragdy (via GitHub)" <gi...@apache.org>.
anuragdy closed pull request #3938: Optimize DefaultThreadContextMap.getCopy() performance
URL: https://github.com/apache/logging-log4j2/pull/3938


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org