-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate Validator Performance
PostPosted: Wed Jul 20, 2011 5:34 pm 
Newbie

Joined: Thu Aug 26, 2010 3:37 pm
Posts: 6
Hi,

I am fairly new to Hibernate Validator and have been trying it out over the last couple of days. One thing I noticed is that the first run of validations is very slow. For example, the first time I ran a set of validations it took just shy of 7 seconds. I then reran the same set of validations on the same exact data set and the second run took only 15 ms. Why the disparity? I'm guessing there's some caching going on so the second run is really fast. Are there any settings I can use that would help the first run perform better?


Top
 Profile  
 
 Post subject: Re: Hibernate Validator Performance
PostPosted: Thu Jul 21, 2011 3:24 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

a difference in validation time is expected, but your case sounds like a lot. How many validations are you executing? How many different beans and how many constraints per bean. I would love to get more information.

If you are validating many different beans, the validation time for the first validation is expected to be slower. The metadata for this particular bean time needs to be created and as you say it will be cached.

Most important performance recommendation is to not throw away the ValidatorFactory. The cache works per factory. Validator instances are lightweight and can be easily re-created.

Depending on your usecase you might want to consider some pre-warming of the caches, but there are no other special options to perform faster. Depending on your usecase and if you have very deep object graphs you could try the failFast which is specific to Hibernate Validator and will stop the validation on the first validation error.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Validator Performance
PostPosted: Thu Jul 21, 2011 8:43 am 
Newbie

Joined: Thu Aug 26, 2010 3:37 pm
Posts: 6
Thank you for the info.

I'm executing roughly 20 validations but the object graph is deep and a few of those validations are on List objects so those validations are iterating through those lists.

Since this is part of a web application, I'm thinking I could build the factory and fire off the validations on app startup just to get that initial "slow" validation run out of the way. Is this a good idea?


Top
 Profile  
 
 Post subject: Re: Hibernate Validator Performance
PostPosted: Thu Jul 21, 2011 9:11 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Sounds reasonable. Can you give a order of magnitude of the elements in the list or maybe the number of validations? Also how many different bean types are involved?


Top
 Profile  
 
 Post subject: Re: Hibernate Validator Performance
PostPosted: Thu Jul 21, 2011 9:37 am 
Newbie

Joined: Thu Aug 26, 2010 3:37 pm
Posts: 6
The list lengths should be fairly small averaging about five to ten objects in the list. There is only one validation being performed on each of the lists right now with the potential for more.

As far as bean types go, our application has a fairly complex XML structure that we unmarshall into JAXB objects. The object graph can get quite deep with roughly 15 nodes being the deepest. Because we have so many different elements within our XML structure there are quite a few bean types as well.

Hopefully that's the kind of info you're looking for.


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

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.