As a little bit of background, we are attempting to do bulk upsert statements for performance in an application. This lead to us generating our own sql from a list of models (1000 records at a time). We were using hibenrate’s native query generator. Since we were generating the sql, we initially implimented parameters positionally, before realizing these are no longer supported. Upong releasing the code and attempting to ingest data we eventually noticed that preparing a query was taking 10x as long as running the query did. Turning on profiling I was able to find that this is the issue: https://github.com/hibernate/hibernate-orm/blob/main/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java @Override public QueryParameterImplementor<?> findQueryParameter(String name) { for ( QueryParameterImplementor<?> queryParameter : queryParameters.keySet() ) { if ( name.equals( queryParameter.getName() ) ) { return queryParameter; } } return null; } The above code is very slow when there are many query parameters. As best I can tell the queryParameters are immutable in this class, only created in the constructor, and new parameters are never added. It looks like it would be very easy to create two maps on initialization that has the name as the key. Though there may be things going on here that I’m not entirely following. Assuming this is all that is necessary I’d be happy to submit a PR if that is helpful. |