After upgrade to Hibernate 6 slower performance when executing query the first time due to ANTLR?

Hello!

We recently upgraded from Java 8 to 17 and in doing so we switched Hibernate Core from 5.4.17.Final to 6.5.3.Final. Now we encountered this weird bug, when a QueryDSL query gets executed for the first time it takes way more time it did before the upgrade.

Before the upgrade when the query got executed the first time it also did take more time than on consecutive calls, but now it takes way more time - like by a factor of 100. If this query is executed again (even with different parameters) the performance is back to normal and it takes less than 50ms.

This seems to happen for rather complex queries.

Here is a screenshot of the profiling:

The method com.querydsl.jpa.impl.AbstractJPAQuery.fetch() took ~95% of all after the upgrade whereas before the upgrade it took only ~30% of all. In addition, there are now many calls to the Antlr library that weren’t there before.

Im not sure if the problem is in Hibernate or in QueryDSL because before the upgrade we used QueryDSL 4.3.1. But after the upgrade we had to switch QueryDSL 5.1.0 (because of jakarta). (I even tested with the QueryDSL OpenFeign fork 6.8 but had the same results.) Therefore, I can’t test it with the older QueryDSL version - or is there a way?

The generated SQL looks kinda the same, but I don’t suspect it’s the SQL because for the second and consecutive executions the performance is good.

Do you have any idea what else I could check? I’m grateful for any advice!

In comparison, profiling the same query before upgrading:

(I couldn’t upload it to the first post due to restrictions of being a new user.)

What are these flamegraph measuring, the wall-clock time for each call? I find it very weird ANTLr parsing takes ~1.5 seconds, could you please paste the query string it’s trying to process?

You could try comparing a pure Hibernate application (without QueryDSL in the way) and comparing performance from version 5 to 6, but it’s the first time we hear of possible problems with the parser so there might be something else going on.

What are these flamegraph measuring, the wall-clock time for each call?

No, it’s CPU time. Sorry for forgetting to mention.

could you please paste the query string it’s trying to process?

This is the query that get’s generated: select ke1_0.domain_object_id, ke1_0.stubObject_creationDateTime, - Pastebin.com

I will try to generate the query with pure Hibernate and also to create a sample project.

Thank you for your support!