Happily, I'm currently having this problem on my project. It takes ages to load the configuration (more than one minute at least). So I played with OptimizeIt quickly.
Our real problem was a little bit tricky (it's based on a special enum implementation we have, we have one custom type per enum type and each enum have a slow static block so each call to UserType.returnedClass is terrible) but I can take a general rule out of it. -> When hibernate is creating its configuration, it's using a huge bunch of classes. All persistent classes and classes related to them. So you spend most of the configuration setup doing two things: XML parsing and class loading. The thing is I'm not quite sure we can do something about this. One other thing that takes time is reflection. I don't know if some calls to ReflectHelper can be replaced by static code but it would help. Without caring about profiling I would have proposed two solutions: 1- Have hibernate being sloppier. I think it's doing a lot of validations when loading the configuration. Maybe we can have a mode where it doesn't do all that. 2- Lazy load the conf. I mean, don't load every file at the beginning, only when the session using the configuration needs it. So for instance load a persistent class only when there's a query on it. Again, a having the two possibilities will be nice (everything at startup or as needed). However, as Gavin said, it might not be possible... One cannot guess where is the class of query he is looking for. It might become possible it we change the approach. For instance having a addLazyClass(Class persistentClass) method so you know that it you need the mapping the the class, you know it's in the hbm.xml having the same name. I want to say that when deployed in an application server, the loading time it takes doesn't matter at all. It's for local testing, when the configuration is loaded often that it causes me problems.. Some guidelines for people having problems: - Don't put too much log on configuration loading, hibernate is pretty verbose in debug. (and for god sakes, don't put them in stdout...) - Try to put in the conf only the classes you really use for a test, not all the application ones. Dynamic hibernate configuration (.addClass() ) really helps for that. - Make sure you don't have any long static block in classes linked to your persistent classes so the class loader will load them quickly. - Load the configuration only once. For instance, do it for a complete test suite, not in each setUp. Once per app server. Hope it helps, Henri P.S.: Something that has nothing to do with what's above. If you have a query "from Player as player where player.team = :team", is it more efficient than "from Player as player where player.team.id = :team" or it doesn't make any difference? ----- Original Message ----- From: "Gavin King" <[EMAIL PROTECTED]> To: "Ara Abrahamian" <[EMAIL PROTECTED]> Cc: "'hibernate-devel'" <[EMAIL PROTECTED]> Sent: Tuesday, April 27, 2004 5:07 PM Subject: Re: [Hibernate] Startup time > Theres other problems with lazy compilation, its not doable. > > Ara Abrahamian wrote: > > >Most probably loading the hbm files and creating metadata objects is the > >bottleneck? And the solution is to lazy load them? > > > >Ara. > > > > > > > >>-----Original Message----- > >>From: [EMAIL PROTECTED] [mailto:hibernate-devel- > >>[EMAIL PROTECTED] On Behalf Of Gavin King > >>Sent: Tuesday, April 27, 2004 12:43 PM > >>To: hibernate-devel > >>Subject: [Hibernate] Startup time > >> > >>OK, I start to hear complaints about the startup time of Hibernate > >>almost everywhere I go now. It's an important issue, because it's a > >>problem that gets worse as people's applications get bigger, and it's > >>something that slows down developers. If there's /anything/ we are > >>about, it is about increasing the speed of development of large > >>applications. So this issue really cuts to the core of what we are > >>trying to achieve here. > >> > >>Max is trying to implement serialization of the SessionFactory, as one > >>possible solution, but perhaps there is some other way we could optimize > >>stuff. Does someone want to profile Hibernate startup, and discover > >>where the slow methods are? At least find out which work is dominating > >>at startup time? > >> > >> > >>-- > >>Gavin King > >>+61 410534454 > >> > >>Hibernate > >>[EMAIL PROTECTED] > >>http://hibernate.org > >> > >>JBoss Inc > >>[EMAIL PROTECTED] > >>http://jboss.com > >> > >> > >> > >>------------------------------------------------------- > >>This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek > >>For a limited time only, get FREE Ground shipping on all orders of $35 > >>or more. Hurry up and shop folks, this offer expires April 30th! > >>http://www.thinkgeek.com/freeshipping/?cpg=12297 > >>_______________________________________________ > >>hibernate-devel mailing list > >>[EMAIL PROTECTED] > >>https://lists.sourceforge.net/lists/listinfo/hibernate-devel > >> > >> > > > > > > > >------------------------------------------------------- > >This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek > >For a limited time only, get FREE Ground shipping on all orders of $35 > >or more. Hurry up and shop folks, this offer expires April 30th! > >http://www.thinkgeek.com/freeshipping/?cpg=12297 > >_______________________________________________ > >hibernate-devel mailing list > >[EMAIL PROTECTED] > >https://lists.sourceforge.net/lists/listinfo/hibernate-devel > > > > > > > -- > Gavin King > +61 410534454 > > Hibernate > [EMAIL PROTECTED] > http://hibernate.org > > JBoss Inc > [EMAIL PROTECTED] > http://jboss.com > > > > ------------------------------------------------------- > This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek > For a limited time only, get FREE Ground shipping on all orders of $35 > or more. Hurry up and shop folks, this offer expires April 30th! > http://www.thinkgeek.com/freeshipping/?cpg=12297 > _______________________________________________ > hibernate-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > ------------------------------------------------------- This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek For a limited time only, get FREE Ground shipping on all orders of $35 or more. Hurry up and shop folks, this offer expires April 30th! http://www.thinkgeek.com/freeshipping/?cpg=12297 _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel