<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" version="2.0">
  <channel>
    <title>Eleutian SpeakENG Development Blog - annoyances</title>
    <link>http://blog.eleutian.com/</link>
    <description />
    <language>en-us</language>
    <copyright>Eleutian Technology</copyright>
    <lastBuildDate>Sat, 15 Dec 2007 19:17:03 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>aaron@eleutian.com</managingEditor>
    <webMaster>aaron@eleutian.com</webMaster>
    <item>
      <trackback:ping>http://blog.eleutian.com/Trackback.aspx?guid=2f6428cf-3603-4eab-b54b-50564c4344ea</trackback:ping>
      <pingback:server>http://blog.eleutian.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.eleutian.com/PermaLink,guid,2f6428cf-3603-4eab-b54b-50564c4344ea.aspx</pingback:target>
      <dc:creator>Aaron</dc:creator>
      <wfw:comment>http://blog.eleutian.com/CommentView,guid,2f6428cf-3603-4eab-b54b-50564c4344ea.aspx</wfw:comment>
      <wfw:commentRss>http://blog.eleutian.com/SyndicationService.asmx/GetEntryCommentsRss?guid=2f6428cf-3603-4eab-b54b-50564c4344ea</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just profiled one of our test assemblies (Unit tests only, nothing hitting the db).
Mocking accounts for 196 seconds out of 357 seconds. The culprit is System.Reflection.Emit.TypeBuilder.CreateType().
This doesn't come as <strong>that</strong> much of a surprise to me, but still...
is there a faster way to do this? Oh and yeah, the results of CreateType are cached
so its only the first time you create a mock of a type that you take this hit, but
still... that can really slow down TDD.
</p>
        <p>
And no, I'm not saying we should stop mocking... just raising awareness.
</p>
        <img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=2f6428cf-3603-4eab-b54b-50564c4344ea" />
      </body>
      <title>Mocking is slow</title>
      <guid isPermaLink="false">http://blog.eleutian.com/PermaLink,guid,2f6428cf-3603-4eab-b54b-50564c4344ea.aspx</guid>
      <link>http://blog.eleutian.com/2007/12/15/MockingIsSlow.aspx</link>
      <pubDate>Sat, 15 Dec 2007 19:17:03 GMT</pubDate>
      <description>&lt;p&gt;
I just profiled one of our test assemblies (Unit tests only, nothing hitting the db).
Mocking accounts for 196 seconds out of 357 seconds. The culprit is System.Reflection.Emit.TypeBuilder.CreateType().
This doesn't come as &lt;strong&gt;that&lt;/strong&gt; much of a surprise to me, but still...
is there a faster way to do this? Oh and yeah, the results of CreateType are cached
so its only the first time you create a mock of a type that you take this hit, but
still... that can really slow down TDD.
&lt;/p&gt;
&lt;p&gt;
And no, I'm not saying we should stop mocking... just raising awareness.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=2f6428cf-3603-4eab-b54b-50564c4344ea" /&gt;</description>
      <comments>http://blog.eleutian.com/CommentView,guid,2f6428cf-3603-4eab-b54b-50564c4344ea.aspx</comments>
      <category>annoyances</category>
      <category>development</category>
    </item>
    <item>
      <trackback:ping>http://blog.eleutian.com/Trackback.aspx?guid=3eb51e05-e80d-4bff-bf68-69be9d5140a0</trackback:ping>
      <pingback:server>http://blog.eleutian.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.eleutian.com/PermaLink,guid,3eb51e05-e80d-4bff-bf68-69be9d5140a0.aspx</pingback:target>
      <dc:creator>Aaron</dc:creator>
      <wfw:comment>http://blog.eleutian.com/CommentView,guid,3eb51e05-e80d-4bff-bf68-69be9d5140a0.aspx</wfw:comment>
      <wfw:commentRss>http://blog.eleutian.com/SyndicationService.asmx/GetEntryCommentsRss?guid=3eb51e05-e80d-4bff-bf68-69be9d5140a0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.amazon.com/Server-2005-Database-Design-Optimization/dp/1590595297/ref=pd_bbs_sr_2/104-6956634-1071903?ie=UTF8&amp;s=books&amp;qid=1188067817&amp;sr=1-2" atomicselection="true">
            <img alt="sqldavidson" src="http://blog.eleutian.com/content/binary/WindowsLiveWriter/NHibernateisgrea.unlessyouwanttooptimize_B063/sqldavidson_1.gif" align="right" />
          </a> First
I want to admit something somewhat embarrassing: I don't know enough about databases.
Until coming here, I've always had a DBA that could handle that. I've started to realize
now how important it is for all developers to have a much better understanding about
databases than I do. So I picked up <a href="http://www.amazon.com/Server-2005-Database-Design-Optimization/dp/1590595297/ref=pd_bbs_sr_2/104-6956634-1071903?ie=UTF8&amp;s=books&amp;qid=1188067817&amp;sr=1-2">this
book</a>. I was really looking to better understand optimization, especially knowing
when to create indexes and optimizing queries. Though the book only had a few chapters
on the subject, I felt like it greatly increased my understanding on the subject.
</p>
        <p>
A few months ago I wrote about <a href="http://blog.eleutian.com/2007/06/01/AdaptiveFetchingStrategiesInORMs.aspx">Adaptive
Fetching Strategies</a>. At that time I had little knowledge about covering indexes
and how they improve performance. Oh well, it's just more reason something like that
should be implemented. Before we even get to that however, NHibernate needs to have
a few features added to it in order to be useful in scenarios where performance is
important.
</p>
        <p>
Remember folks, <a href="http://weblogs.asp.net/jgalloway/archive/2007/07/18/the-real-reason-select-queries-are-bad-index-coverage.aspx">SELECT
* is bad</a>. NHibernate is for effectively always doing a SELECT * when you're asking
for an object when it comes to index coverage. Yes, it specifies columns so it doesn't
have <strong>all</strong> the problems associated with SELECT *, but it is still decidedly
less performant than querying for only what you want. Compound this with the extra
overhead the unneeded columns add during a flush, and you've got a pretty compelling
argument to only query for what you need.
</p>
        <p>
OK, so you've decided that you only want to query for what you need and you're using
NHibernate. Well, you can do that... kind of. Not much differently than you can if
you just used ADO.NET and DataSets though. NHibernate doesn't support lazy field initialization.
This means that if you query for only username and email address from your user table,
you don't get back a User. You get back a List of object[]'s. Arguably a list of object[]'s
is less functional than a DataSet. Combine this with the fact that you're querying
using HQL, which has a subset of functionality, predictability, and therefore optimizability
of real SQL, and you start to see a big hole in whole ORM thing... if you want to
optimize your pages. Yes, HQL does make writing queries more pretty and more in the
domain, but it would be nice if it supported things like "on".
</p>
        <p>
Obviously optimizing too early is evil, but we've had several pages now where we've
needed to optimize, and just resorted to querying for a table of values. No longer
are we querying for objects, that's just not performant enough. Especially in display
scenarios where you're not making changes to anything as NHibernate lacks the ability
to do read-only queries, so you end up with that (very) expensive flush unless you
change your flushing strategy to be manual (awkward) or you detach your objects from
the session (also awkward).
</p>
        <p>
So in short, I feel NHibernate (and any ORM for that matter) needs the following features
to really be optimization friendly:
</p>
        <ul>
          <li>
Lazy field initialization 
</li>
          <li>
Querying for partial objects: <strong>select u(Username, Email) from User u</strong></li>
          <li>
Read-only queries that do not get flushed. 
</li>
          <li>
Join qualifiers (on in T-SQL)</li>
        </ul>
        <p>
And yeah, I know it's open source and I could just do it myself, but I have nightmares
about that codebase, and I hardly have the time to implement such large features.
All I have the time to do is complain and wish :)
</p>
        <img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=3eb51e05-e80d-4bff-bf68-69be9d5140a0" />
      </body>
      <title>NHibernate is great... unless you want to optimize</title>
      <guid isPermaLink="false">http://blog.eleutian.com/PermaLink,guid,3eb51e05-e80d-4bff-bf68-69be9d5140a0.aspx</guid>
      <link>http://blog.eleutian.com/2007/08/25/NHibernateIsGreatUnlessYouWantToOptimize.aspx</link>
      <pubDate>Sat, 25 Aug 2007 19:28:29 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.amazon.com/Server-2005-Database-Design-Optimization/dp/1590595297/ref=pd_bbs_sr_2/104-6956634-1071903?ie=UTF8&amp;amp;s=books&amp;amp;qid=1188067817&amp;amp;sr=1-2" atomicselection="true"&gt;&lt;img alt="sqldavidson" src="http://blog.eleutian.com/content/binary/WindowsLiveWriter/NHibernateisgrea.unlessyouwanttooptimize_B063/sqldavidson_1.gif" align="right"&gt;&lt;/a&gt; First
I want to admit something somewhat embarrassing: I don't know enough about databases.
Until coming here, I've always had a DBA that could handle that. I've started to realize
now how important it is for all developers to have a much better understanding about
databases than I do. So I picked up &lt;a href="http://www.amazon.com/Server-2005-Database-Design-Optimization/dp/1590595297/ref=pd_bbs_sr_2/104-6956634-1071903?ie=UTF8&amp;amp;s=books&amp;amp;qid=1188067817&amp;amp;sr=1-2"&gt;this
book&lt;/a&gt;. I was really looking to better understand optimization, especially knowing
when to create indexes and optimizing queries. Though the book only had a few chapters
on the subject, I felt like it greatly increased my understanding on the subject.
&lt;/p&gt;
&lt;p&gt;
A few months ago I wrote about &lt;a href="http://blog.eleutian.com/2007/06/01/AdaptiveFetchingStrategiesInORMs.aspx"&gt;Adaptive
Fetching Strategies&lt;/a&gt;. At that time I had little knowledge about covering indexes
and how they improve performance. Oh well, it's just more reason something like that
should be implemented. Before we even get to that however, NHibernate needs to have
a few features added to it in order to be useful in scenarios where performance is
important.
&lt;/p&gt;
&lt;p&gt;
Remember folks, &lt;a href="http://weblogs.asp.net/jgalloway/archive/2007/07/18/the-real-reason-select-queries-are-bad-index-coverage.aspx"&gt;SELECT
* is bad&lt;/a&gt;. NHibernate is for effectively always doing a SELECT * when you're asking
for an object when it comes to index coverage. Yes, it specifies columns so it doesn't
have &lt;strong&gt;all&lt;/strong&gt; the problems associated with SELECT *, but it is still decidedly
less performant than querying for only what you want. Compound this with the extra
overhead the unneeded columns add during a flush, and you've got a pretty compelling
argument to only query for what you need.
&lt;/p&gt;
&lt;p&gt;
OK, so you've decided that you only want to query for what you need and you're using
NHibernate. Well, you can do that... kind of. Not much differently than you can if
you just used ADO.NET and DataSets though. NHibernate doesn't support lazy field initialization.
This means that if you query for only username and email address from your user table,
you don't get back a User. You get back a List of object[]'s. Arguably a list of object[]'s
is less functional than a DataSet. Combine this with the fact that you're querying
using HQL, which has a subset of functionality, predictability, and therefore optimizability
of real SQL, and you start to see a big hole in whole ORM thing... if you want to
optimize your pages. Yes, HQL does make writing queries more pretty and more in the
domain, but it would be nice if it supported things like "on".
&lt;/p&gt;
&lt;p&gt;
Obviously optimizing too early is evil, but we've had several pages now where we've
needed to optimize, and&amp;nbsp;just resorted to querying for a table of values. No longer
are we querying for objects, that's just not performant enough. Especially in display
scenarios where you're not making changes to anything as NHibernate lacks the ability
to do read-only queries, so you end up with that (very) expensive flush unless you
change your flushing strategy to be manual (awkward) or you detach your objects from
the session (also awkward).
&lt;/p&gt;
&lt;p&gt;
So in short, I feel NHibernate (and any ORM for that matter) needs the following features
to really be optimization friendly:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Lazy field initialization 
&lt;li&gt;
Querying for partial objects: &lt;strong&gt;select u(Username, Email) from User u&lt;/strong&gt; 
&lt;li&gt;
Read-only queries that do not get flushed. 
&lt;li&gt;
Join qualifiers (on in T-SQL)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
And yeah, I know it's open source and I could just do it myself, but I have nightmares
about that codebase, and I hardly have the time to implement such large features.
All I have the time to do is complain and&amp;nbsp;wish&amp;nbsp;:)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=3eb51e05-e80d-4bff-bf68-69be9d5140a0" /&gt;</description>
      <comments>http://blog.eleutian.com/CommentView,guid,3eb51e05-e80d-4bff-bf68-69be9d5140a0.aspx</comments>
      <category>annoyances</category>
      <category>development</category>
      <category>nhibernate</category>
      <category>open source</category>
    </item>
    <item>
      <trackback:ping>http://blog.eleutian.com/Trackback.aspx?guid=669975bb-30f4-4527-b716-3ff7cecb41c2</trackback:ping>
      <pingback:server>http://blog.eleutian.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.eleutian.com/PermaLink,guid,669975bb-30f4-4527-b716-3ff7cecb41c2.aspx</pingback:target>
      <dc:creator>Aaron</dc:creator>
      <wfw:comment>http://blog.eleutian.com/CommentView,guid,669975bb-30f4-4527-b716-3ff7cecb41c2.aspx</wfw:comment>
      <wfw:commentRss>http://blog.eleutian.com/SyndicationService.asmx/GetEntryCommentsRss?guid=669975bb-30f4-4527-b716-3ff7cecb41c2</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <pre class="csharpcode">
          <span class="kwrd">using</span> NUnit.Framework;
[TestFixture] <span class="kwrd">public</span><span class="kwrd">class</span> OperatorExplicitTests
{ <span class="kwrd">public</span><span class="kwrd">interface</span> IFoo { } <span class="kwrd">public</span><span class="kwrd">sealed</span><span class="kwrd">class</span> Foo
: IFoo { } <span class="kwrd">public</span><span class="kwrd">class</span> Bar :
IFoo { <span class="kwrd">private</span> Foo _foo = <span class="kwrd">new</span> Foo(); <span class="kwrd">public</span><span class="kwrd">static</span><span class="kwrd">explicit</span><span class="kwrd">operator</span> Foo(Bar
bar) { <span class="kwrd">return</span> bar._foo; } } [Test] <span class="rem">//
Passes</span><span class="kwrd">public</span><span class="kwrd">void</span> TestCastFromClass()
{ Bar bar = <span class="kwrd">new</span> Bar(); Foo foo = (Foo)bar; } [Test] <span class="rem">//
Passes</span><span class="kwrd">public</span><span class="kwrd">void</span> TestCastFromInterfaceToNormal()
{ IFoo bar = <span class="kwrd">new</span> Bar(); Foo foo = (Foo)(Bar)bar; } [Test] <span class="rem">//
Throws System.InvalidCastException: Unable to cast object of type 'Bar' to type 'Foo'.</span><span class="kwrd">public</span><span class="kwrd">void</span> TestCastFromInterface()
{ IFoo bar = <span class="kwrd">new</span> Bar(); Foo foo = (Foo)bar; } }</pre>
        <p>
Ugh, see what happens when you try to be sneaky? Is this a bug? A limitation? 
</p>
        <p>
If you're curious why I care, we have a custom implentation of IDbCommand that wraps
a SqlCommand and <a href="https://svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate/src/NHibernate/Impl/SqlClientBatchingBatcher.cs">this
code</a> expects it to be a SqlCommand... no fooling it I guess :/
</p>
        <img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=669975bb-30f4-4527-b716-3ff7cecb41c2" />
      </body>
      <title>Operator explicit fubar'd</title>
      <guid isPermaLink="false">http://blog.eleutian.com/PermaLink,guid,669975bb-30f4-4527-b716-3ff7cecb41c2.aspx</guid>
      <link>http://blog.eleutian.com/2007/03/28/OperatorExplicitFubard.aspx</link>
      <pubDate>Wed, 28 Mar 2007 07:15:48 GMT</pubDate>
      <description>&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; NUnit.Framework; [TestFixture] &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; OperatorExplicitTests
{ &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IFoo { } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Foo
: IFoo { } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Bar :
IFoo { &lt;span class="kwrd"&gt;private&lt;/span&gt; Foo _foo = &lt;span class="kwrd"&gt;new&lt;/span&gt; Foo(); &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;explicit&lt;/span&gt; &lt;span class="kwrd"&gt;operator&lt;/span&gt; Foo(Bar
bar) { &lt;span class="kwrd"&gt;return&lt;/span&gt; bar._foo; } } [Test] &lt;span class="rem"&gt;//
Passes&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; TestCastFromClass()
{ Bar bar = &lt;span class="kwrd"&gt;new&lt;/span&gt; Bar(); Foo foo = (Foo)bar; } [Test] &lt;span class="rem"&gt;//
Passes&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; TestCastFromInterfaceToNormal()
{ IFoo bar = &lt;span class="kwrd"&gt;new&lt;/span&gt; Bar(); Foo foo = (Foo)(Bar)bar; } [Test] &lt;span class="rem"&gt;//
Throws System.InvalidCastException: Unable to cast object of type 'Bar' to type 'Foo'.&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; TestCastFromInterface()
{ IFoo bar = &lt;span class="kwrd"&gt;new&lt;/span&gt; Bar(); Foo foo = (Foo)bar; } }&lt;/pre&gt;
&lt;p&gt;
Ugh, see what happens when you try to be sneaky? Is this a bug? A limitation? 
&lt;/p&gt;
&lt;p&gt;
If you're curious why I care, we have a custom implentation of IDbCommand that wraps
a SqlCommand and &lt;a href="https://svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate/src/NHibernate/Impl/SqlClientBatchingBatcher.cs"&gt;this
code&lt;/a&gt;&amp;nbsp;expects it to be a SqlCommand... no fooling it I guess :/
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.eleutian.com/aggbug.ashx?id=669975bb-30f4-4527-b716-3ff7cecb41c2" /&gt;</description>
      <comments>http://blog.eleutian.com/CommentView,guid,669975bb-30f4-4527-b716-3ff7cecb41c2.aspx</comments>
      <category>annoyances</category>
      <category>development</category>
      <category>nhibernate</category>
    </item>
  </channel>
</rss>