I have recently done an upgrade from Hibernate 5.6.9 to 6.1.1 and then to 6.1.2. In the project I have 1100+ tests, the vast majority of which are integration tests using an in-memory H2 database (2.1.214 to be specific). In the 5.x version, the total execution time of all the tests was stable, around 40 seconds. After the upgrade, however, itincreased to around 2 minutes.
After doing a ton of measurements, it seemed the culprit is the save method from JpaRepository, the total execution time of which has increased 20-fold.
WIth the 5.6.9 library, I have the following total execution times for the different methods, while executing all of the tests:
Timer : Total elapsed time for save: 3002 ms
Timer : Total elapsed time for saveAll: 38 ms
Timer : Total elapsed time for flush: 0 ms
Timer : Total elapsed time for saveFlush: 2 ms
Timer : Total elapsed time for fetch: 4678 ms (this includes all other methods not covered by the timers above, including find/findAll/findById/findByWhateverElse)
And after upgrading to 6.1.1 and 6.1.2, I have these numbers:
Timer : Total elapsed time for save: 88748 ms
Timer : Total elapsed time for saveAll: 322 ms
Timer : Total elapsed time for flush: 0 ms
Timer : Total elapsed time for saveFlush: 1 ms
Timer : Total elapsed time for fetch: 5247 ms
The additional 85 seconds in the save method pretty much corresponds to the increase of execution time from 40 seconds to 2 minutes.
Now here the problem is that this is a Spring interface, so the source of the issue is still not clear, so I dug deeper and have found org.hibernate.internal.SessionImpl, which seems to be the interface between Spring and Hibernate. As the next step I have instrumented the most promising methods of both the 5.6.9 and 6.1.2 versions of this class and reran my full test suite.
The results were the following. For 5.6.9 (just the relevant times):
Timer : Total elapsed time for em_persist: 0 ms
Timer : Total elapsed time for em_merge: 3736 ms
Timer : Total elapsed time for save: 2627 ms
And for 6.1.2:
Timer : Total elapsed time for em_persist: 167 ms
Timer : Total elapsed time for em_merge: 92310 ms
Timer : Total elapsed time for save: 86115 ms
Now clearly I have messed something up a little bit with the instrumentation, because there is no way that the merge function calls took 92 seconds, when the save calls on the repositories took only 86 seconds (and in case of the 5.6.9 version, also 3.7 seconds, when the total save calls there took 2.6 seconds). But it is also clear that between 5.6.9 and 6.1.2, Hibernate itself became significantly slower saving data, and that the slowdown is not coming from the Spring data/jpa parts.
Now my question is, does anyone have any idea where I should start looking for the source of the issue? Is there maybe some fancy new setting that I should be tweaking to get back the old performance?