Working with nHibernate can be very convenient and easy to use, but there are some issues to pay attention to.
Some of the biggest time-waste on every running scenario are related to nHibernate.
With good implementation, you can magnificently improve your services performance.
Here are some implementation issues you can easily change in order to improve nHibernate performance:
1. Remove unnecessary "lazy=false" attributes in the mapping.
It's making nHibernate (and Sql) to work hard since nHibernate is picking up all the associations stated in the mapping and place them into cache, while most of the time there is no use of the data coming back.
If you need – try to add "Fetch" in the code
2. Remove unnecessary objects from the criteria.
It's making nHibernate to work hard for preparing the objects, even if you are not using the data.
3. Pay attention to objects that have "type=json" in their mapping.
If they have no "Equals" method in the class, it can cause nHibernate to update the data for every time you are using the objects, even if nothing was changed.
4. Pay attention to mapping casting.
nHibernate automatically convert string properties to nvarchar(4000)
If you have a column in "varchar" type, use "type=AnsiString" in the mapping.
It will save lots of casting time from SQL.
After adding the AnsiString property – The SQL is 5 times faster than before:
Application Software Engineer