Skip to content

Conversation

@Sanne
Copy link
Member

@Sanne Sanne commented Jul 4, 2025

https://hibernate.atlassian.net/browse/HHH-19593 ResourceRegistryStandardImpl triggers identity hashcode on Statements and ResultSets

In our attempt to make sure we correctly lose all Statements and ResultsSets, the implementation of ResourceRegistryStandardImpl is triggering identity hashcode to be assigned on these objects, which is not very efficient - the overhead of these operations is noticeable in several benchmarks.

Considering the majority of simple operations on Hibernate will use a single Statement/ResultSet pair, we should optimise our tracking based on this.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Jul 4, 2025

Thanks for your pull request!

This pull request does not follow the contribution rules. Could you have a look?

❌ All commit messages should start with a JIRA issue key matching pattern HHH-\d+
    ↳ Offending commits: [ce195a5]

› This message was automatically generated.

…Statements and ResultSets

This reverts commit ef2207f17d328d00ead2c372a6d311fe1b26a432.
@Sanne Sanne requested a review from Copilot July 4, 2025 15:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces a generic Map-based tracking of JDBC Statement/ResultSet pairs with specialized containers that optimize the common single-entry case to avoid identity‐hashcode overhead.

  • Introduce ResultsetsTrackingContainer and ResultSetsSet for fast‐path single‐entry tracking and overflow to maps.
  • Refactor ResourceRegistryStandardImpl and its ExtendedState to use the new containers and adjust cleanup.
  • Update JdbcCoordinatorImpl logging to guard expensive tracev calls and add comprehensive unit tests for the new containers.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/main/java/org/hibernate/resource/jdbc/internal/ResultsetsTrackingContainer.java New tracking container with fast-path for one statement
src/main/java/org/hibernate/resource/jdbc/internal/ResultSetsSet.java New set container optimized for one ResultSet
src/main/java/org/hibernate/resource/jdbc/internal/ResourceRegistryStandardImpl.java Refactor to use new containers; update closeAll and ExtendedState
src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java Guard tracev calls with TRACE_ENABLED
src/test/java/org/hibernate/resource/jdbc/internal/ResultsetsTrackingContainerTest.java Unit tests for ResultsetsTrackingContainer
src/test/java/org/hibernate/resource/jdbc/internal/ResultSetsSetTest.java Unit tests for ResultSetsSet

@Sanne Sanne merged commit 1b5d95c into hibernate:main Jul 4, 2025
25 of 26 checks passed
@Sanne Sanne deleted the HHH-19593 branch July 4, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant