﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>PandaWood commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>Can we assume that using Attributes instead of XML mappings remove all of this startup time?
  
  
I'm a tad surprised no one mentioned attributes at all given the relative extreme counter-ideas that are being thrown around. I appreciate that migrating to attributes from XML would be a great task, but they at least deserve a mention somewhere in the discussion... ?
  
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment18</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment18</guid><pubDate>Wed, 31 Oct 2007 01:03:39 GMT</pubDate></item><item><title>Jim Bolla commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>In the NH trunk, there is already code that generates C# classes from the xml schema for the mapping document. There is already code that can convert an entire mapping document into an object graph of those classes via XmlSerialization. The mapping document parser is already PARTIALLY taking advantage of this, and will eventually COMPLETELY utilize this as the first step to go from XML to fully realized NH objects.
  
  
The fully realized objects cannot be guaranteed to be serialized, partially because one can define new types in one's own assemblies outside the control of NH. Plus the order of operations is significant. This is where these schema objects come into play. They are very simple classes that are fully serializable. This would allow them to be cached via binary serialization to disk. Some rudimentary performance tests on this were promising.
  
  
In theory, one could build a fluent builder interface around these objects to allow definition of the mapping documents in C# as opposed to XML. (And still not be mixed in with your domain objects like the MappingAttributes stuff.) That would actually be pretty awesome I think. But that can't happen until I get the code migration done. (That idea kinda motivates me to get back into it. Damn real life in the way.)
  
  
FYI, much of the relevant code is under these folders:
  
  
https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/
  
https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/
  
  
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment17</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment17</guid><pubDate>Fri, 26 Oct 2007 18:11:33 GMT</pubDate></item><item><title>Ayende Rahien commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>Mike D,
  
The startup times in this case is for the scale far-out scenario. In practice, the startup times are not usually meaningful.
  
If you want to avoid hacking XML, use ActiveRecord, it makes things much eaiser.
  
  
And I don't agree with the "let us just change this tiny bit" approach, it doesn't work in practice.
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment16</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment16</guid><pubDate>Fri, 26 Oct 2007 15:17:53 GMT</pubDate></item><item><title>Mike D commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>I’m with Frans, this is one of those areas where code generation shines. Consider a DSL such as active writer which could store the map in xml and generate c# on the fly. Problem solved without pre-build steps. For others that like manually hacking xml use a pre-build c# code generator.
  
  
This is one of the reasons I don’t use nHibernate, great product, I just don’t like hacking xml and can’t afford the startup times. Why recompile something each time an app launches, waste of time and energy. 
  
  
Another improvement that could be made is to break the map into two parts, schema and map, the map acts as a bridge between the schema and the objects. So if you convert a relation from 1:N to N:N you only change the schema and all maps update.
  
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment15</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment15</guid><pubDate>Fri, 26 Oct 2007 15:06:06 GMT</pubDate></item><item><title>Ben Scheirman commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>Ayende, that makes perfect sense.  Great ideas!
  
  
I definitely 2nd the approach for "boobernate" but maybe under a different name...  I do have to get clients to approve this stuff, ya know!
  
  
It would be great to have an NHibernate API for serializing/deserializing whatever gets output from the Configuration, seems like it would be a bunch of hashtables (for settings and the reflection cache) -- and also the mapping format in memory.  All of that sounds serializable, so I think your approach could bear fruit.
  
  
I'm thinking something like this:
  
  
Configuration cfg = new Configruation();
  
//add assembly
  
SessionFactory factory = cfg.BuildsessionFactory();
  
  
NHibernate.Utility.PersistConfiguration(config, factory, "config-cache.nhconfig" );
  
  
slap that into a pre-build Nant/MSBuild task and then you can do this in your application:
  
  
if( File.Exists("config-cache.nhconfig") )
  
{
  
       SessionFactory factory =     NHibernate.Utility.LoadConfigurationCache("config-cache.nhconfig");
  
}
  
else
  
{
  
     // do it the old way
  
}
  
  
  
I'm not entirely sure what those methods would look like off the top of my head, but it seems doable.
  
  
Thoughts?
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment14</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment14</guid><pubDate>Fri, 26 Oct 2007 14:15:48 GMT</pubDate></item><item><title>Jim Bolla commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>I've actually started refactoring/recoding the XML mapping parsing bits in the NH trunk.
  
  
My goal is to be able to use XML deserialization to turn the xml documents into an object graph of simple objects. The effect of this is that this DTO-like object graph could also be binary serialized/deserialized. Currently the mapping parser takes the XML data and directly turns that into more heavyweight NH objects that often cannot be serialized all in one step. Once this process is split into two steps, a schema caching step could be introduced to speed up startup time by more than a few seconds. This is not an insignificant improvement for desktop applications.
  
  
So far its been a pretty significant effort (most of this processing was done in one large static class) and I haven't had much time to work on it recently with moving and starting a new job. I will get back to it once the dust settles.
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment13</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment13</guid><pubDate>Fri, 26 Oct 2007 12:52:23 GMT</pubDate></item><item><title>Ayende Rahien commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>Philip,
  
My first approach would be to slap Serializable on everything, and then see what works and what not.
  
Writing custom binary formats is not something that I wish to do.
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment12</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment12</guid><pubDate>Fri, 26 Oct 2007 10:44:41 GMT</pubDate></item><item><title>Ayende Rahien commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>Frans,
  
Yes, that is the next step.
  
I don't think that it would be C# code for this. I experimented with Code DOM based persistence, it is nice idea, but awkward to maintain.
  
I think that we will simply allow to save and load a session factory.
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment11</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment11</guid><pubDate>Fri, 26 Oct 2007 10:43:32 GMT</pubDate></item><item><title>Ayende Rahien commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>Alessandro,
  
Create a second configuration file, and instead of specifying &lt;assembly&gt;, specify just &lt;resource&gt; with the relevant resources.
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment10</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment10</guid><pubDate>Fri, 26 Oct 2007 10:41:54 GMT</pubDate></item><item><title>Ayende Rahien commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>Tomas,
  
Yes, it is doing XSD validation. And that takes most of the time.
  
There is no way to build the configuration without that, am I worry about default values and stuff that are in the configuration that may be missed.
  
From a simple attempt, AddReaderUnvalidate did have a significant performance boost.
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment9</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment9</guid><pubDate>Fri, 26 Oct 2007 10:24:59 GMT</pubDate></item><item><title>Philip L&amp;#248;ventoft commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>I am interested in maybe doing the patch, but how would you go about it? I guess we would have to make some sort of binary file format for NHibernate configurations. Another possibility would be to make a compiler for the mappings, for example to a binary file format and do it as a pre-build step, then it should be possible to load it very fast. What do you think?
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment8</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment8</guid><pubDate>Fri, 26 Oct 2007 08:15:27 GMT</pubDate></item><item><title>Frans Bouma commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>Here's a tip from the code-generation Gilde :)
  
Why don't you generate C# code as an option for the XML interpretation, where the C# code simply builds the inner structures build otherwise from the xml data. You can even have a commandline tool which does that at compile time (pre-build actually) where the C# code is embedded into the main program, OR, where the generated code is in a separate assembly and loaded on demand by nhibernate.
  
  
Sure, you lose the 'flexibility' of changing mappings for production systems. well... who wants to have that option is really not that sane... 
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment7</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment7</guid><pubDate>Fri, 26 Oct 2007 08:10:53 GMT</pubDate></item><item><title>Alessandro C. commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>Regarding to initialize only a subset of entities using a staring session factory and after replace it with a global session factory, how can I decide which entities include in a session factory and which in another session factory?
  
I only have a assembly with all my entities inside.
  
  
Thanks
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment6</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment6</guid><pubDate>Fri, 26 Oct 2007 07:18:12 GMT</pubDate></item><item><title>Christiaan Baes commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>Thanks for looking at my problem, I will change it soon and make it faster.
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment5</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment5</guid><pubDate>Fri, 26 Oct 2007 05:57:04 GMT</pubDate></item><item><title>nichols.mike.s AT gmail.com (Mike Nichols) commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>Since I've fallen in like with Binsor I'd like Binsor for NHibernate...
  
Maybe Boobernate.
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment4</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment4</guid><pubDate>Fri, 26 Oct 2007 03:27:33 GMT</pubDate></item><item><title>Tomas Restrepo commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>Is NHibernate actually doing XSD validation on the documents? If so, could it be disabled and see if that improves things somewhat? If not, then what exactly does NHibernate to read all the configuration documents, then? I mean, 1000 files should generate a bit of IO, but not enough to account for such a big difference by itself (though I guess it is building the DOM that results in that).
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment3</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment3</guid><pubDate>Fri, 26 Oct 2007 02:58:18 GMT</pubDate></item><item><title>Jason commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>This problem was raised at ALT.NET. One of the ideas that was tossed around was persistable configuration which you mention above. Another possible solution that was discussed was to JIT the session factory. I'm sure that if this is a bad idea you'll tell me!
  
  
Certainly I think that it would be beneficial to do something here because database integration tests are slow anyway and spending 10 secs to build the session factory is too long. Maybe the community can agree upon an approach and then we can take care of implementation?
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment2</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment2</guid><pubDate>Fri, 26 Oct 2007 02:54:53 GMT</pubDate></item><item><title>Eber Irigoyen commented on Real World NHibernate: Reducing startup times for large amount of entities</title><description>death to XML =o), XML is sloooooww
</description><link>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment1</link><guid>http://ayende.com/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities#comment1</guid><pubDate>Fri, 26 Oct 2007 02:50:15 GMT</pubDate></item></channel></rss>