<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Performance</title>
        <link>http://www.mostlylucid.net/category/19.aspx</link>
        <description>Performance</description>
        <language>en-US</language>
        <copyright>Scott Galloway</copyright>
        <generator>Subtext Version 2.1.0.5</generator>
        <item>
            <title>Obsessive Coding, optimal string Reverse...</title>
            <link>http://mostlylucid.net/archive/2008/02/04/obsessive-coding-optimal-string-reverse.aspx</link>
            <description>I love this type of thing, a whole post on &lt;a href="http://weblogs.asp.net/justin_rogers/archive/2004/06/10/153175.aspx"&gt;optimal string reverse algorithms&lt;/a&gt;. I always love this sort of thing, learning huge amounts of detail about fundamental operations (sort of, umm when do you ever reverse strings?). Actually looking at &lt;a href="http://weblogs.asp.net/justin_rogers/"&gt;Justin Rogers' blog&lt;/a&gt; he has &lt;a href="http://weblogs.asp.net/justin_rogers/archive/tags/Performance/default.aspx"&gt;lots of great performance posts&lt;/a&gt;...&lt;img src="http://mostlylucid.net/aggbug/1239.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Scott Galloway</dc:creator>
            <guid>http://mostlylucid.net/archive/2008/02/04/obsessive-coding-optimal-string-reverse.aspx</guid>
            <pubDate>Mon, 04 Feb 2008 17:00:41 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2008/02/04/obsessive-coding-optimal-string-reverse.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1239.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Why do so many people mess up Singletons?</title>
            <link>http://mostlylucid.net/archive/2008/01/27/why-do-so-many-people-mess-up-singletons.aspx</link>
            <description>&lt;p&gt;I've written about this a few times now (use the search thingy to find where) but I'm still surprised how many people mess up the Singleton pattern.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;For instance take:&lt;/p&gt;  &lt;p&gt;if (blogSettingsSingleton == null)   &lt;br /&gt;                {    &lt;br /&gt;                    blogSettingsSingleton = new BlogSettings();    &lt;br /&gt;                }    &lt;br /&gt;                return blogSettingsSingleton;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Looks ok, right? But this is a classic poor pattern when dealing with multi-threaded apps. Why? Look at the initial 'if' statement, and think what happens if multiple treads hit this at the same time...one thread could be in the process of creating this object whilst the others are evaluating the condition...&lt;/p&gt;  &lt;p&gt;If you're using &lt;a href="http://en.wikipedia.org/wiki/Singleton_pattern"&gt;Singletons&lt;/a&gt; PLEASE read &lt;a href="http://www.yoda.arachsys.com/csharp/singleton.html"&gt;this article&lt;/a&gt;. The singleton pattern article from Wikipedia has the following excellent implementation of a singleton:&lt;/p&gt;  &lt;pre class="code"&gt;/// &amp;lt;summary&amp;gt;
/// Class implements singleton pattern.
/// &amp;lt;/summary&amp;gt;
public class Singleton
{
        // Private constructor to avoid other instantiation
        // This must be present otherwise the compiler provide 
        // a default public constructor
        private Singleton()
        {
        }
 
        /// &amp;lt;summary&amp;gt;
        /// Return an instance of &amp;lt;see cref="Singleton"/&amp;gt;
        /// &amp;lt;/summary&amp;gt;
        public static Singleton Instance
        {
            get
            {
                /// An instance of Singleton wont be created until the very first 
                /// call to the sealed class. This a CLR optimization that ensure that
                /// we have properly lazy-loading singleton. 
                return SingletonCreator.CreatorInstance;
            }
        }
 
        /// &amp;lt;summary&amp;gt;
        /// Sealed class to avoid any heritage from this helper class
        /// &amp;lt;/summary&amp;gt;
        private sealed class SingletonCreator
        {
          // Retrieve a single instance of a Singleton
          private static readonly Singleton _instance = new Singleton();
 
          /// &amp;lt;summary&amp;gt;
          /// Return an instance of the class &amp;lt;see cref="Singleton"/&amp;gt;
          /// &amp;lt;/summary&amp;gt;
          public static Singleton CreatorInstance
          {
            get { return _instance; }
          }
        }
}
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/pre&gt;

&lt;p&gt;This is a lazy-initializing, thread safe singleton...does sacrifice *some* performance (see the &lt;a href="http://www.yoda.arachsys.com/csharp/singleton.html"&gt;earlier article&lt;/a&gt; for details of this) but it is FAR safer than the original I showed...&lt;/p&gt;

&lt;p&gt;Oh, and one last thing...are you REALLY sure you need a Singleton? One horrible pattern I've seen is code is using Singletons to access database connections...this is VERY RARELY required and sacrifices a lot of the benefits which modern databases offer for concurrent access.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;font color="#ff0000"&gt;UPDATE:&lt;/font&gt; Umm...realized that I don't explain what a 'Singleton' is...essentially it's a pattern which limits the access of an object to a single caller at a time. Common uses for Singletons could be accessing files on a file-system where you really want to make sure that only one thread has access at one time. Oh, and to make things even more complicated you'd more commonly want to use a &lt;a href="http://msdn2.microsoft.com/en-us/library/system.threading.readerwriterlock(VS.71).aspx"&gt;ReaderWriterLock&lt;/a&gt; in this scenario to allow many readers or a single writer...only &lt;a href="http://msdn.microsoft.com/msdnmag/issues/06/06/ConcurrentAffairs/"&gt;of course you wouldn't&lt;/a&gt;...told you it was complicated! Oh, and to further complicate matters in VS2008 and above you'd probably want &lt;a href="http://www.bluebytesoftware.com/blog/PermaLink,guid,c4ea3d6d-190a-48f8-a677-44a438d8386b.aspx"&gt;ReaderWriterLockSlim&lt;/a&gt;!&lt;/p&gt;&lt;img src="http://mostlylucid.net/aggbug/1238.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Scott Galloway</dc:creator>
            <guid>http://mostlylucid.net/archive/2008/01/27/why-do-so-many-people-mess-up-singletons.aspx</guid>
            <pubDate>Mon, 28 Jan 2008 00:47:55 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2008/01/27/why-do-so-many-people-mess-up-singletons.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1238.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Really nice article on .NET Data Access</title>
            <link>http://mostlylucid.net/archive/2005/04/07/really-nice-article-on-.net-data-access.aspx</link>
            <description>&lt;a href="http://weblogs.asp.net/ssmith/"&gt;Steven Smith&lt;/a&gt; has a &lt;a href="http://aspalliance.com/articleViewer.aspx?aId=626&amp;amp;pId=-1"&gt;great little article&lt;/a&gt; on &lt;a href="http://aspalliance.com/"&gt;ASPAllicance&lt;/a&gt; on comparing performance and methods of performing data access in .NET applications. Some really interesting techniques there, I especially like the &lt;a href="http://aspalliance.com/articleViewer.aspx?aId=526&amp;amp;pId=-1"&gt;IDataReader delegate example&lt;/a&gt;, a really nice solution to passing IDataReaders between layers in an app…&lt;img src="http://mostlylucid.net/aggbug/1050.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Blog Author</dc:creator>
            <guid>http://mostlylucid.net/archive/2005/04/07/really-nice-article-on-.net-data-access.aspx</guid>
            <pubDate>Thu, 07 Apr 2005 17:37:00 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2005/04/07/really-nice-article-on-.net-data-access.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/1050.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Nested repeaters - new article on Codeproject and why you shouldn't do it that way!</title>
            <link>http://mostlylucid.net/archive/2004/02/21/nested-repeaters---new-article-on-codeproject-and-why-you.aspx</link>
            <description>&lt;p&gt;Just been reading &lt;a href="http://www.codeproject.com/aspnet/AspNetNestedRepeaters.asp"&gt;this article&lt;/a&gt; on &lt;a href="http://www.codeproject.com/"&gt;Codeproject.com&lt;/a&gt;...hmm...I have a few issues with how he does things:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;DataBinder.Eval - I have what is becoming an obsession about this now - there's just NO NEED for this in most cases, it sucks in terms of performance (you can typically lose about 20% compared to the stongly typed method. I've posted a couple of times about this &lt;a href="http://www.mostlylucid.co.uk/posts/668.aspx"&gt;here &lt;/a&gt;and &lt;a href="http://www.mostlylucid.co.uk/posts/664.aspx"&gt;here&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;OnItemDataBound - now, I've yet to do a benchmark comparing to member methods (just reminded myself actually, I might do one this weekend). I use to use this method &lt;a href="http://www.mostlylucid.co.uk/posts/650.aspx"&gt;all the time&lt;/a&gt; for nested repeaters until I saw the light and moved on to &lt;a href="http://www.mostlylucid.co.uk/posts/748.aspx"&gt;Member Methods&lt;/a&gt; - which as well as feeling a lot 'cleaner' than the event based approach - I feel will be significantly faster - since it avoids the overhead of events and casting required for the ItemDataBound approach.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;So anyway, I will put my money where my mouth is and finally get down to writing an article about the relative merits of these approaches...but the bits I've mentioned above are based on a LOT of uses in real applications - believe me I make these suggestions not on a whim but based on a lot of trial and error!&lt;/p&gt;&lt;img src="http://mostlylucid.net/aggbug/755.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Blog Author</dc:creator>
            <guid>http://mostlylucid.net/archive/2004/02/21/nested-repeaters---new-article-on-codeproject-and-why-you.aspx</guid>
            <pubDate>Sat, 21 Feb 2004 19:15:00 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2004/02/21/nested-repeaters---new-article-on-codeproject-and-why-you.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/755.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Web Service Compression - really nice implementation of a Web Service Extension (with sample)</title>
            <link>http://mostlylucid.net/archive/2004/01/24/web-service-compression---really-nice-implementation-of-a-web.aspx</link>
            <description>&lt;p&gt;I've posted about this topic a few times, it's really nice to see that someone has finally given a practical, free method of doing this. &lt;a href="http://weblogs.asp.net/pglavich/archive/2004/01/24/62475.aspx"&gt;This implementation&lt;/a&gt; uses WS-E to do this, meaning that you add an attirbute to both the client and server portions of your web service - and there you have it, a compressed SOAP message!&lt;br /&gt;If you're using Web Services and transmitting any non-trivial amount of Data, I really do recommend that you use compression on the SOAP message (especially if you're sending DataSets, those buggers are huge when serialized - of course you can minimize them &lt;a href="http://www.eggheadcafe.com/articles/20031219.asp"&gt;in a different way&lt;/a&gt;), this is a very simple, intelligent approach to this problem, it can actually make Web Services practical where they weren't before (as transmission latency can actually preclude their use in some circumstances).&lt;br /&gt;Anyway, good job &lt;a href="http://weblogs.asp.net/pglavich/"&gt;Glav&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;&lt;font color="#ff0000"&gt;UPDATE:&lt;/font&gt;  Just found &lt;a href="http://www.dotnetjunkies.com/Tutorial/90D3B3E0-6544-4594-B3BA-E41D8F381324.dcik"&gt;this article&lt;/a&gt; on &lt;a href="http://www.dotnetjunkies.com"&gt;DotNetJunkies&lt;/a&gt; - which seems to offer HTTP 1.1 compression for web services - yet to try it out (looking at the date it's possible it would only work for .NET 1.0 - but I'll give it a try and report the results!)&lt;/p&gt;&lt;img src="http://mostlylucid.net/aggbug/721.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Blog Author</dc:creator>
            <guid>http://mostlylucid.net/archive/2004/01/24/web-service-compression---really-nice-implementation-of-a-web.aspx</guid>
            <pubDate>Sat, 24 Jan 2004 22:32:00 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2004/01/24/web-service-compression---really-nice-implementation-of-a-web.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/721.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Another article in the offing...hopefully...if I get round to it...Member methods versus OnItemDataBound for nested Data List controls</title>
            <link>http://mostlylucid.net/archive/2004/01/22/another-article-in-the-offing.hopefully.if-i-get-round-to-it.member.aspx</link>
            <description>&lt;p&gt;A very common question in the &lt;a href="http://www.asp.net/forums"&gt;ASP.NET Forums&lt;/a&gt;is "How do I nest one Repeater (or DataList or DataGrid) inside of another?"; well, my usual stock answer used to be to use the OnItemDataBound event then use a FindControl() to find the Repeater inside the template and set it's datasource to the child view - then just DataBind...Recently though, I've gone against this - based in part on a bit in a book by Farhan Muhammad and Matt Milner (can't find the link to the exact book, but &lt;a href="http://www.amazon.co.uk/exec/obidos/ASIN/1590590724/mostlylucid-21"&gt;this one &lt;/a&gt;is pretty useful too), essentially, it involves using a member method. So, instead of hooking up the event you simply specify the DataSource of the Child Repeater as follows (for example)  &lt;br /&gt;
&amp;lt;asp:Repeater id=FormatsRepeater DataSource="&amp;lt;%# GetFormats(Container.DataItem)%&amp;gt;" Runat="Server"&amp;gt;&lt;br /&gt;
, along with the rest of the templates etc for the child repeater. Then, in code (the codebehind normally), you simply do this: &lt;font size="1"&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff" size="1"&gt;public&lt;/font&gt;&lt;font size="1"&gt; DataView GetFormats(&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;object&lt;/font&gt;&lt;font size="1"&gt; DataItem)&lt;br /&gt;{&lt;br /&gt;DataRowView di = DataItem &lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;as&lt;/font&gt;&lt;font size="1"&gt; DataRowView;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;if&lt;/font&gt;&lt;font size="1"&gt;(di!=&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;null&lt;/font&gt;&lt;font size="1"&gt;)&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;return&lt;/font&gt;&lt;font size="1"&gt; di.CreateChildView(&lt;/font&gt;&lt;font color="#800000" size="1"&gt;"JobCount"&lt;/font&gt;&lt;font size="1"&gt;);&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;else&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;return&lt;/font&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="1"&gt;null&lt;/font&gt;&lt;font size="1"&gt;;&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="1"&gt;&lt;/font&gt;Hmm..&lt;a href="http://blogjet.com/"&gt;BlogJet&lt;/a&gt; isn't great at letting me modify HTML - I'll sort this later...anyway, as you can see, very simple code (incidentally, should mention, I'm using a DataSet with a &lt;a href="http://www.dotnetjohn.com/articles.aspx?articleid=63"&gt;DataRelation&lt;/a&gt; called JobCount). What's the upshot of all of this...well, the Member Method version, as well as (IMHO) being much easier to write than the ItemDataBound version - is also MUCH faster - in some tests, twice as fast! Anyway, I will hopefully write a bigger piece on this with some stats to prove my point - if I get round to it :-)&lt;/p&gt;&lt;img src="http://mostlylucid.net/aggbug/716.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Blog Author</dc:creator>
            <guid>http://mostlylucid.net/archive/2004/01/22/another-article-in-the-offing.hopefully.if-i-get-round-to-it.member.aspx</guid>
            <pubDate>Thu, 22 Jan 2004 19:19:00 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2004/01/22/another-article-in-the-offing.hopefully.if-i-get-round-to-it.member.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/716.aspx</wfw:commentRss>
        </item>
        <item>
            <title>More on my Load Testing fun...</title>
            <link>http://mostlylucid.net/archive/2004/01/21/more-on-my-load-testing-fun.aspx</link>
            <description>&lt;p&gt;Well, still at it (20 hours after starting - yes, the time on this post is correct!). Really fustrating mostly, but one of those times coding where hours and hours of pain (literally in this case - flu and splitting headaches were involved) were followed by a sudden dawning then a solution.&lt;br /&gt;Well, I've learnt more about Load Testing and SQL Server performance today than I had in the previous 2 years, lessons I've learnt:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;SQL Profiler is god's own tool (not in any nasty sordid way, in a good way) - use it, love it! If you're running a load test, run Sql profiler at the same time...then look at the results, taking special note of reads and duration of queries...then...&lt;/li&gt;&lt;li&gt;Use SQL Query Analyzer's 'show execution plan' option, look at the little graph carefully, looking for places where lots of non-indexed table scans are happening / a  whole lot of work is going on where you don't expect it!#&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;It turned out that my problem was to do with a trigger firing on inserts, this updated a stats table which locked my main table - resulting in a bad Deadlock...as long as I had free connections it was fine, but the connections following the insert which queried the same data were getting hung because of the trigger's lock - so the number of connections racked up, eventually causing timeouts and other horridness...&lt;/p&gt;&lt;p&gt;Incidentally, I came across the rudest, most unhelpful Sales rep on the planet today (my opinion only!), a certain load testing tool company (the No.1 in the world apparently - god knows why!), I needed an eval license to do a quick run through of the load testing script my client was using - so I applied for an eval license from the website, downloaded and installed the tool - so far so good! Now, if this product was good enough, my company would probably have sprung for a license - problem is that they 'don't offer eval licenses in Europe' - implication was that I'd use it to rip them off. Alternative, spend an afternoon with their sales guy or spend $10000 on a product which I've never used (an afternoon would mean rouchly £5000 lost earnings for my company). My alternative was to use the free eval of another company's tool (won't mention the name yet in case&lt;em&gt; &lt;/em&gt;I hate it) - so the first company have just lost a potential sale. &lt;/p&gt;&lt;p&gt;If you offer an eval download - especially one that requires you to install the software before you can even apply for a liocense - make damn sure you mention that there's not actually one available!&lt;/p&gt;&lt;img src="http://mostlylucid.net/aggbug/714.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Blog Author</dc:creator>
            <guid>http://mostlylucid.net/archive/2004/01/21/more-on-my-load-testing-fun.aspx</guid>
            <pubDate>Wed, 21 Jan 2004 09:57:00 GMT</pubDate>
            <comments>http://mostlylucid.net/archive/2004/01/21/more-on-my-load-testing-fun.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.net/comments/commentRss/714.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>
