Limitation of metamodel imports cache causes severe performance drops in large projects

Description

introduces an unconfigurable, hard limitation of the metamodel imports cache to 1000 entries for the purpose of avoiding an OOM in environments using dynamically generated aliases in HQL queries.

Unfortunately this causes severe performance drops in large projects containing much more than 1000 persistent classes and query aliases and also a large amount of classes in the classpath.

In our project (a large spring boot application using hibernate 5.6.4) we already have about 1800 persistent classes contained in the imports cache after metamodel initialization, so every alias contained in a HQL-Query results in a call of ClassLoaderService::classForName() for a string never representing an existing class, which is very expensive and takes multiple seconds to return (with a ClassLoadingException).

This lead to severe performance issues in many places of our application, so we were forced to overcome the limitation of the imports cache. Unfortunately the limitation is implemented by a hardcoded literal (“1_000”), so we had no chance other than to temporarily fork our private hibernate version and remove the limitation completely.

We therefore urgently suggest the introduction of a configuration parameter instead of the hardcoded literal, so that it is possible to increase or remove the limit of the imports cache, depending on the requirements of the individual application.

Activity

Show:

Sanne Grinovero August 26, 2022 at 8:34 AM

We're trying hard to not need to add additional configuration properties, but rather embrace principles of ergonomics.

So we've fixed the issue by ensuring that the actual number of entity classes doesn't count towards the limit; that will avoid to suddenly hit this obscure limit with large applications, but will still penalize applications which generate an unreasonable number of pseudo-random meaningless tokens.

I think that's a reasonble solution in scope of a relatively urgent bugfix; we can also revisit this to improve the overall pattern further - I've included a couple of possible suggestions in the comment code but we'll only explore such directions if there's further evidence of this being needed. Also I'd prefer to explore such directions in the context of an enhancement rather than a regression bugfix.

Réda Housni Alaoui August 18, 2022 at 5:46 PM

Pull request opened at

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Created March 1, 2022 at 6:03 PM
Updated August 31, 2022 at 10:11 AM
Resolved August 26, 2022 at 8:34 AM