Skip to content

HHH-19668 Reduce size of collections held in ParameterInterpretationImpl before storing them in the cache #10670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ public static <T> Set<T> toSmallSet(Set<T> set) {
* The goal is to save memory.
*/
public static <K, V> Map<K, V> toSmallMap(final Map<K, V> map) {
if ( map == null ) {
return emptyMap();
}
return switch ( map.size() ) {
case 0 -> emptyMap();
case 1 -> {
Expand All @@ -363,6 +366,9 @@ public static <K, V> Map<K, V> toSmallMap(final Map<K, V> map) {
* The goal is to save memory.
*/
public static <V> List<V> toSmallList(ArrayList<V> arrayList) {
if ( arrayList == null ) {
return emptyList();
}
return switch ( arrayList.size() ) {
case 0 -> emptyList();
case 1 -> singletonList( arrayList.get( 0 ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty;
import static org.hibernate.internal.util.collections.CollectionHelper.makeCopy;
import static org.hibernate.internal.util.collections.CollectionHelper.toSmallList;
import static org.hibernate.internal.util.collections.CollectionHelper.toSmallMap;
import static org.hibernate.internal.util.type.PrimitiveWrapperHelper.getDescriptorByPrimitiveType;
import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_LOCK_MODE;
import static org.hibernate.query.results.internal.Builders.resultClassBuilder;
Expand Down Expand Up @@ -1742,9 +1744,9 @@ private static class ParameterInterpretationImpl implements ParameterInterpretat

public ParameterInterpretationImpl(ParameterRecognizerImpl parameterRecognizer) {
this.sqlString = parameterRecognizer.getAdjustedSqlString();
this.parameterList = parameterRecognizer.getParameterList();
this.positionalParameters = parameterRecognizer.getPositionalQueryParameters();
this.namedParameters = parameterRecognizer.getNamedQueryParameters();
this.parameterList = toSmallList( parameterRecognizer.getParameterList() );
this.positionalParameters = toSmallMap( parameterRecognizer.getPositionalQueryParameters() );
this.namedParameters = toSmallMap( parameterRecognizer.getNamedQueryParameters() );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.QueryException;
Expand Down Expand Up @@ -36,7 +35,7 @@ private enum ParameterStyle {

private int ordinalParameterImplicitPosition;

private List<ParameterOccurrence> parameterList;
private ArrayList<ParameterOccurrence> parameterList;
private final StringBuilder sqlStringBuffer = new StringBuilder();

public ParameterRecognizerImpl() {
Expand Down Expand Up @@ -81,7 +80,7 @@ public Map<Integer, QueryParameterImplementor<?>> getPositionalQueryParameters()
return positionalQueryParameters;
}

public List<ParameterOccurrence> getParameterList() {
public ArrayList<ParameterOccurrence> getParameterList() {
return parameterList;
}

Expand Down