From 7309cdeb662b2d49c1f550c28b4b643b24c6b3a3 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Sat, 22 Jun 2019 23:22:20 +0100 Subject: [PATCH] HHH-13450 Do not compute the full role name of a collection unless necessary --- .../engine/internal/TwoPhaseLoad.java | 19 ++++++++++++------- .../loader/AbstractEntityJoinWalker.java | 2 +- .../walking/internal/FetchStrategyHelper.java | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java index f687a6f2aa..6fbe1dd7df 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java @@ -313,7 +313,7 @@ public final class TwoPhaseLoad { String associationName, Type type) { if ( type.isAssociationType() || type.isCollectionType() ) { - Boolean overridingEager = isEagerFetchProfile( session, entityName + "." + associationName ); + Boolean overridingEager = isEagerFetchProfile( session, entityName, associationName ); if ( LOG.isDebugEnabled() ) { if ( overridingEager != null ) { @@ -331,14 +331,19 @@ public final class TwoPhaseLoad { return null; } - private static Boolean isEagerFetchProfile(SharedSessionContractImplementor session, String role) { + private static Boolean isEagerFetchProfile(SharedSessionContractImplementor session, String entityName, String associationName) { LoadQueryInfluencers loadQueryInfluencers = session.getLoadQueryInfluencers(); - for ( String fetchProfileName : loadQueryInfluencers.getEnabledFetchProfileNames() ) { - FetchProfile fp = session.getFactory().getFetchProfile( fetchProfileName ); - Fetch fetch = fp.getFetchByRole( role ); - if ( fetch != null && Fetch.Style.JOIN == fetch.getStyle() ) { - return true; + // Performance: avoid concatenating entityName + "." + associationName when there is no need, + // as otherwise this section becomes an hot allocation point. + if ( loadQueryInfluencers.hasEnabledFetchProfiles() ) { + final String role = entityName + '.' + associationName; + for ( String fetchProfileName : loadQueryInfluencers.getEnabledFetchProfileNames() ) { + FetchProfile fp = session.getFactory().getFetchProfile( fetchProfileName ); + Fetch fetch = fp.getFetchByRole( role ); + if ( fetch != null && Fetch.Style.JOIN == fetch.getStyle() ) { + return true; + } } } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java b/hibernate-core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java index 7b22952ee8..d102859fee 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java @@ -151,7 +151,7 @@ public abstract class AbstractEntityJoinWalker extends JoinWalker { String relativePropertyPath = pos >= 0 ? fullPath.substring( pos ) : rootPropertyName; - String fetchRole = persister.getEntityName() + "." + relativePropertyPath; + String fetchRole = persister.getEntityName() + '.' + relativePropertyPath; for ( String profileName : getLoadQueryInfluencers().getEnabledFetchProfileNames() ) { final FetchProfile profile = getFactory().getFetchProfile( profileName ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/walking/internal/FetchStrategyHelper.java b/hibernate-core/src/main/java/org/hibernate/persister/walking/internal/FetchStrategyHelper.java index afbe99fad8..70d46f62ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/walking/internal/FetchStrategyHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/walking/internal/FetchStrategyHelper.java @@ -58,7 +58,7 @@ public final class FetchStrategyHelper { final String relativePropertyPath = pos >= 0 ? fullPath.substring( pos ) : rootPropertyName; - final String fetchRole = persister.getEntityName() + "." + relativePropertyPath; + final String fetchRole = persister.getEntityName() + '.' + relativePropertyPath; for ( String profileName : loadQueryInfluencers.getEnabledFetchProfileNames() ) { final FetchProfile profile = loadQueryInfluencers.getSessionFactory().getFetchProfile( profileName );