-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Performance issue in class ...engine.internal.Cascade
PostPosted: Tue Jun 30, 2015 11:34 am 
Newbie

Joined: Tue Jun 30, 2015 10:54 am
Posts: 1
Hi,
it seems, that the implementation of org.hibernate.engine.internal.Cascade has a poor influence to performance in big transactions.

In flush prepare operations, Hibernate checks each property on every entity that is part of the transaction cache:
- First: Hibernate reads the property value via reflection
- Second: Hibernate checks if the property is already an entity type or not

If the second step finds out, that it is not an entity type, the reflection of the first step was needless

When sampling the transaction flush, we found out, that the useless reflection has a poor influence to performance in big transactions. Even Hibernate 5 has this code:

Code:
public final class Cascade {
        ...
   public void cascade(final EntityPersister persister, final Object parent, final Object anything) {
                ...
            else if ( action.requiresNoCascadeChecking() ) {
               action.noCascade(
                     eventSource,
                     persister.getPropertyValue( parent, i ),   // Here we have the 'expensive' reflection
                     parent,
                     persister,
                     i
               );
               ....

Code:
public static final CascadingAction PERSIST_ON_FLUSH = new BaseCascadingAction() {
        ...
      public void noCascade(
            EventSource session,
            Object child,
            Object parent,
            EntityPersister persister,
            int propertyIndex) {
         if ( child == null ) {
            return;
         }
         Type type = persister.getPropertyTypes()[propertyIndex];
         if ( type.isEntityType() ) {                             // And here we decide not to check the child
                                ...
         }
      }
        ....


Our sampling has shown, that the hole org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(AutoFlushEvent) method lasts 150.207ms. About 30% of the time he made useless reflection: org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(Object, int) lasts 52.902ms.

IMHO a quick solution would be:
- First: Check the property type and only if it is an entity make second step
- Second: Get property value

Do you think, this analysis is correct.

Best regards
Guido


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.