<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://bloggingabout.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tag 'performance'</title><link>http://bloggingabout.net/search/SearchResults.aspx?a=1&amp;o=DateDescending&amp;tag=performance&amp;orTags=0</link><description>Search results matching tag 'performance'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Don’t use Activator.CreateInstance or ConstructorInfo.Invoke, use compiled lambda expressions</title><link>http://bloggingabout.net/blogs/vagif/archive/2010/04/02/don-t-use-activator-createinstance-or-constructorinfo-invoke-use-compiled-lambda-expressions.aspx</link><pubDate>Fri, 02 Apr 2010 15:43:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:483053</guid><dc:creator>VagifAbilov</dc:creator><description>&lt;p&gt;For a long time I’ve been under impression that rule engine that comes with Microsoft Windows Workflow Foundation is slow, very slow. We used it to execute some of our business rules, and soon found out that rule processing slows down application execution. What was strange is that the rules were really simple and it was hard to believe that an industry-strength rule engine uses so long time on processing them.&lt;/p&gt;  &lt;p&gt;Eventually I ran a profiler, and it immediately showed where the time was spent. In fact it was not the actual rule validation but preparation for it: instantiation of the WF rule parser. The parser class is not public, so we used a trick to obtain its instance: retrieved its non-public constructor information via reflection and then called Invoke.&lt;/p&gt;  &lt;p&gt;This was sloooow. So slow that we noticed it in our integration tests. What made it noticeable is that after we converted some of our business rules to use WF rule engine, we were encouraged by results and move more rules to use the same techinque. In the end rule validation was called many times during a single business operation, and performance deteriorated.&lt;/p&gt;  &lt;p&gt;My first approach to this issue was to cache validated rules, and it worked. The total time to execute integration tests was reduced by 50%. However, I was not quite happy with the situation: we have various places where objects are instantiated using reflection, caching is not always possible and in general complicates component design. Recently I reviewed the code of &lt;a href="http://structuremap.github.com/structuremap/index.html" target="_blank"&gt;StructureMap&lt;/a&gt; (I like reading good code), and remembered that it no longer used reflection and instead instantiated dependencies using compiled lambda expressions.&lt;/p&gt;  &lt;p&gt;Roger Alsing in &lt;a href="http://rogeralsing.com/2008/02/28/linq-expressions-creating-objects/" target="_blank"&gt;this post&lt;/a&gt; presented a generic method that can be used as a replacement for constructor method invocation. The essence of the method is in it’s last three lines:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;// Make a NewExpression that calls the ctor with the args we just created
NewExpression newExp = Expression.New(ctor, argsExp);                  

// Create a lambda with the New expression as body and our param object[] as arg
LambdaExpression lambda = Expression.Lambda(typeof(ObjectActivator), newExp, param);              

// Compile it
ObjectActivator compiled = (ObjectActivator)lambda.Compile();&lt;/pre&gt;

&lt;p&gt;Although lambda expressions are part of LINQ (and you have to import System.Linq.Expressions namespace to manage them), as we can see from this example, they can be very useful to solve core language tasks, such as object instantiation.&lt;/p&gt;

&lt;p&gt;But what is the gain? The gain is huge bringing the performance close to the speed of native IL code. I wrote a few tests to measure performance of object creation in different scenarios: by calling ‘new’ constructor, Activator.CreateInstance, ConstructorInfo.Invoke and using compiled lambda expression. Here are the results:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;DefaultConstructor_Activator: (0,20 ms per 1000 calls)
DefaultConstructor_CompiledExpression: (0,04 ms per 1000 calls)
DefaultConstructor_Invoke: (1,07 ms per 1000 calls)
DefaultConstructor_New: (0,02 ms per 1000 calls)
DefaultConstructor_NotCompiledExpression: (169,00 ms per 1000 calls)
NonDefaultConstructor_Activator: (3,39 ms per 1000 calls)
NonDefaultConstructor_CompiledExpression: (0,07 ms per 1000 calls)
NonDefaultConstructor_Invoke: (1,57 ms per 1000 calls)
NonDefaultConstructor_New: (0,02 ms per 1000 calls)
NonDefaultConstructor_NotCompiledExpression: (293,00 ms per 1000 calls)&lt;/pre&gt;

&lt;p&gt;Results says it all, especially when arranged in a graph.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://bloggingabout.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vagif.metablogapi/3022.Chart_5F00_4A95396D.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="Chart" border="0" alt="Chart" src="http://bloggingabout.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vagif.metablogapi/7217.Chart_5F00_thumb_5F00_55552173.png" width="533" height="526" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I removed from the graph the results for not compiled lambda expressions, because they make other figures insignificant. But it is important to remember that compilation should be performed only once, so the code should be carefully reviewed to avoid occasional recompilcation of lambdas.&lt;/p&gt;

&lt;p&gt;P.S. The title of this blog post may look provocative, and of course I don’t really mean somebody should completely stop using Activator.CreateInstance. Compilation of labmda expressions is expensive enough to limit it’s practical use. But there are certain use cases (like IoC frameworks) when it gives clear performance advantage.&lt;/p&gt;</description></item><item><title>Speeding up startup time for applications that use NHibernate</title><link>http://bloggingabout.net/blogs/ramon/archive/2010/03/30/speeding-up-startup-time-for-applications-that-use-nhibernate.aspx</link><pubDate>Tue, 30 Mar 2010 20:57:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:483040</guid><dc:creator>Ramon Smits</dc:creator><description>&lt;p&gt;I just read a very cool NHibernate trick to let your application start faster that was mentioned by Ricardo Peres:&lt;/p&gt;
&lt;pre&gt;Configuration cfg = new Configuration().Configure();
IFormatter serializer = new BinaryFormatter();

using (Stream stream = File.OpenWrite(&amp;quot;Configuration.serialized&amp;quot;))
{
   serializer.Serialize(stream, cfg);
}

...

using (Stream stream = File.OpenRead(&amp;quot;Configuration.serialized&amp;quot;))
{
   cfg = serializer.Deserialize(stream) as Configuration;
}
&lt;/pre&gt;</description></item><item><title>Using the CrossListQueryInfo and CrossListQueryCache</title><link>http://bloggingabout.net/blogs/bas/archive/2009/03/27/using-the-crosslistqueryinfo-and-crosslistquerycache.aspx</link><pubDate>Fri, 27 Mar 2009 09:56:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:481424</guid><dc:creator>Bas</dc:creator><description>&lt;p&gt;Lately, I am relatively a lot working with the CrossListQueryInfo. This is a way to query multiple lists at once, crossing multiple SPWebs, if you want to. And, the main reason why I used it, it&amp;#39;s possible to use the cached lists of the sitecollection, to improve performance! The first steps with this CrossListQueryInfo can be quite frustrating, as there isnt too much documentation to find on.&lt;/p&gt;
&lt;p&gt;I will start with a code sample, to show how to use this to query multuple webs to retrieve Items with the contentType News Item OR Location News Item from the publishing pages. When you are going to the CrossListQueryInfo, it&amp;acute;s smart to make use of&amp;nbsp;U2U&amp;acute;s Caml Query Builder, to quickly build up thecaml that you want use.&lt;br /&gt;Things to keep in mind while using the &lt;span style="color:#2b91af;"&gt;CrossListQueryInfo:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#2b91af;"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="color:#000000;"&gt;The results that are returned are ONLY PUBLISHED items. I was breaking my head around this one, because I was sure that my query was good, the CAML Query builder also returned a result, but the &lt;span style="color:#2b91af;"&gt;CrossListQueryCache&lt;/span&gt;&amp;nbsp;didn&amp;#39;t. After publishing, all the results showed up properly&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#000000;"&gt;ViewFields: Insert the fields that you want to see. If there is a field inside that doesnt exist in the list that you query, your result will be nill, nada, nothing. Make sure that you put in the INTERNAL field names!&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#000000;"&gt;RowLimit: When filling in value &amp;#39;0&amp;#39;, you won&amp;#39;t see any results&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#000000;"&gt;When using the&amp;nbsp;&lt;span style="color:#2b91af;"&gt;CrossListQueryCache&lt;/span&gt;&amp;nbsp;, make sure not to use the GetSiteData that uses the SPWeb param:&amp;nbsp;GetSiteData(SPWeb web) and GetSiteData(SPWeb web, SPSiteDataQuery query) DO NOT use caching!!&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color:#000000;"&gt;and make sure to use &lt;a href="http://msdn2.microsoft.com/en-us/ms461685"&gt;&lt;span style="color:#cc6600;"&gt;Microsoft.SharePoint.WebPartPages.WebPart&lt;/span&gt;&lt;/a&gt;! This WebPart inherits from&amp;nbsp;&lt;a href="http://msdn2.microsoft.com/en-us/h0t1fxe7"&gt;&lt;span style="color:#cc6600;"&gt;System.Web.UI.WebControls.WebParts.WebPart&lt;/span&gt;&lt;/a&gt; and enhances it with some extra functionality for connected webparts, client-side programming and data caching!! Thanks to &lt;a href="http://blog.mastykarz.nl/"&gt;Waldek Mastykarz&lt;/a&gt;&amp;nbsp;for sharing this info.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;"&gt;Below is an example of a query that queries all the Publishing pages libraries that resides in the current SPWeb and all childWebs.&lt;/span&gt;&lt;/p&gt;
&lt;div style="font-family:Courier New;font-size:10pt;color:black;background:white;"&gt;
&lt;p&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;DataTable&lt;/span&gt; ExampleQuery()&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; clqi = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;CrossListQueryInfo&lt;/span&gt;();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Insert the list types that you want to use. In this case, its the publishing page library (850, see code below)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; clqi.Lists = &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;Lists ServerTemplate=\&amp;quot;&amp;quot;&lt;/span&gt; + (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;ListServerTemplateCodes&lt;/span&gt;.PageLibrary + &lt;span style="color:#a31515;"&gt;&amp;quot;\&amp;quot; /&amp;gt;&amp;quot;&lt;/span&gt;; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Insert the fields that you want to see. If there is a field inside that doesnt exist in the list that you query, your result will be nill, nada, nothing.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Make sure that you put in the INTERNAL field names!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; clqi.ViewFields = &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;FieldRef Name=\&amp;quot;Title\&amp;quot; /&amp;gt;&amp;lt;FieldRef Name=\&amp;quot;FileLeafRef\&amp;quot; /&amp;gt;&amp;lt;FieldRef Name=\&amp;quot;Nieuws_x0020_Type\&amp;quot; /&amp;gt;&amp;lt;FieldRef Name=\&amp;quot;Nieuws_x0020_Leverancier\&amp;quot; /&amp;gt;&amp;lt;FieldRef Name=\&amp;quot;Uitgelicht\&amp;quot; /&amp;gt;&amp;lt;FieldRef Name=\&amp;quot;Created\&amp;quot; /&amp;gt;&amp;lt;FieldRef Name=\&amp;quot;Comments\&amp;quot; /&amp;gt;&amp;quot;&lt;/span&gt;;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// scop to use. Another possibility is SiteCollection&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; clqi.Webs = &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;Webs Scope=\&amp;quot;Recursive\&amp;quot; /&amp;gt;&amp;quot;&lt;/span&gt;;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// turn the cache on&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; clqi.UseCache = &lt;span style="color:blue;"&gt;true&lt;/span&gt;;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// if row limit == 0, you will get 0 results&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; clqi.RowLimit = 100;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// I know a stringbuilder would be better, but i wanted to show the markup of the query&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; clqi.Query = &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;OrderBy&amp;gt;&amp;quot;&lt;/span&gt; + &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;FieldRef Name=&amp;#39;Title&amp;#39; /&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;/OrderBy&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;Where&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;Or&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;Eq&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;FieldRef Name=&amp;#39;ContentType&amp;#39; /&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;Value Type=&amp;#39;Text&amp;#39;&amp;gt;News Item&amp;lt;/Value&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;/Eq&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;Eq&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;FieldRef Name=&amp;#39;ContentType&amp;#39; /&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;Value Type=&amp;#39;Text&amp;#39;&amp;gt;LocationNews Item&amp;lt;/Value&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;/Eq&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;/Or&amp;gt;&amp;quot;&lt;/span&gt; +&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;/Where&amp;gt;&amp;quot;&lt;/span&gt;;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// put the CrossListQueryInfo object into the CrossListQueryCache&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;CrossListQueryCache&lt;/span&gt; clqc = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;CrossListQueryCache&lt;/span&gt;(clqi);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// and query the data!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// make sure: the GetSiteData(SPWeb web) and GetSiteData(SPWeb web, SPSiteDataQuery query) DO NOT use caching!!!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;DataTable&lt;/span&gt; tbl = clqc.GetSiteData((&lt;span style="color:#2b91af;"&gt;SPContext&lt;/span&gt;.Current.Site, &lt;span style="color:#2b91af;"&gt;CrossListQueryCache&lt;/span&gt;.ContextUrl());&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// return the datatable&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;return&lt;/span&gt; tbl;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;The enum below can be used to make life a little bit easier. I got it from: &lt;a href="http://www.aspenhorizons.com/devblog/?p=29"&gt;http://www.aspenhorizons.com/devblog/?p=29&lt;/a&gt;&lt;/p&gt;
&lt;div style="font-family:Courier New;font-size:10pt;color:black;background:white;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;enum&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ListServerTemplateCodes&lt;/span&gt;&lt;/div&gt;
&lt;div style="font-family:Courier New;font-size:10pt;color:black;background:white;"&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GenericList = 100,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; DocumentLibrary = 101,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Survey = 102,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; LinksList = 103,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AnnouncementsList = 104,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ContactsList = 105,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EventsList = 106,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TasksList = 107,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; DiscussionBoard = 108,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; PictureLibrary = 109,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; DataSources = 110,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; SiteTemplateGallery = 111, &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; UserInformationList = 112,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; WebPartGallery = 113,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ListTemplateGallery = 114,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; XMLFormLibrary = 115,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MasterPagesGallery = 116,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; NoCodeWorkflows = 117,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CustomWorkflowProcess = 118,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; WikiPageLibrary = 119,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CustomGridForAList = 120,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; DataConnectionLibrary = 130,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; WorkflowHistory = 140,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; GanttTasksList = 150,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MeetingSeriesList = 200,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MeetingAgendaList = 201,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MeetingAttendeesList = 202,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MeetingDecisionsList = 204,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MeetingObjectivesList = 207,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MeetingTextBox = 210,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MeetingThingsToBringList = 211,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MeetingWorkspacePagesList = 212,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; PortalSitesList = 300,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; BlogPostsList = 301,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; BlogCommentsList = 302,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; BlogCategoriesList = 303,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; PageLibrary = 850,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IssueTracking = 1100,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AdministratorTasksList = 1200, &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; PersonalDocumentLibrary = 2002,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; PrivateDocumentLibrary = 2003&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;more information about this subject can be found at: &lt;/p&gt;
&lt;a href="http://sharepoint.nailhead.net/2008/04/musing-on-crosslistquerycache-class.html"&gt;http://sharepoint.nailhead.net/2008/04/musing-on-crosslistquerycache-class.html&lt;/a&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;</description></item><item><title>The Myth of Stored Procedures Preference</title><link>http://bloggingabout.net/blogs/adelkhalil/archive/2008/01/05/the-myth-of-stored-procedures-preference.aspx</link><pubDate>Sat, 05 Jan 2008 22:16:28 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:453656</guid><dc:creator>Adel Khalil</dc:creator><description>&lt;p&gt;When looking to the Stored Proscedures debate, there is always those three factors you should measure by.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Productivity&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;- Span code base over multiple staging environments is a pain and harder to maintain.&lt;/p&gt; &lt;p&gt;- Versioning sp code is way harder than versioning application code.&lt;/p&gt; &lt;p&gt;- Minor change to the design require changing in both the SPs and the DAL code.&lt;/p&gt; &lt;p&gt;- Todays IDEs are more advanced than most of the RDBMS offers, implementing on IDEs is obviously preferable.&lt;/p&gt; &lt;p&gt;- Switching between two seprate world to implement single method is always pain.&lt;/p&gt; &lt;p&gt;- It&amp;#39;s impossible to cover every single scenario and write SP for it, which will lead to write these SP as you go, huge consistency problem.&lt;/p&gt; &lt;p&gt;- There is no way to only update single param in the Update method using SPs as there isn&amp;#39;t optional parameters, on every update you need to supply full param collection.&lt;/p&gt; &lt;p&gt;- SPs are not portable if you want to develop application that run over multiple DBMS you will be writing SPs for each DBMS, standard SQL is portable.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;- Big myth over here, using SPs not guarante best security practice and certinly dosn&amp;#39;t mean that your application is SQL Injection proof you can write code like this&lt;/p&gt; &lt;p&gt;string s = &amp;quot;EXEC sp_GetCustomerByEmail &amp;#39;&amp;quot; + txtEmailAddress.Text + &amp;quot;&amp;#39;&amp;quot;;&lt;/p&gt; &lt;p&gt;and you will be using SP and still open to all kind of SQL Injection.&lt;/p&gt; &lt;p&gt;- Another myth regarding security is that if you are using Ad-hoc queries you *most likely* grand permissions for CRUD operations for your application user on the database, no you are not, that&amp;#39;s why Views are invented.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;often when SPs vs. Ad-hoc queries debate intoduced the performance card played, SPs advocates says SPs are pre-compiled which is not let met quate like &lt;a href="http://weblogs.asp.net/fbouma/archive/2003/11/18/38178.aspx" target="_blank"&gt;Frans&lt;/a&gt; did from SQL Server Books Online&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#626262"&gt;SQL Server 2000 and SQL Server version 7.0 incorporate a number of changes to statement processing that extend many of the performance benefits of stored procedures to all SQL statements. SQL Server 2000 and SQL Server 7.0 do not save a partially compiled plan for stored procedures when they are created. A stored procedure is compiled at execution time, like any other Transact-SQL statement. SQL Server 2000 and SQL Server 7.0 retain execution plans for all SQL statements in the procedure cache, not just stored procedure execution plans.&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;So with no pre-compilation and caching for both SPs and SQL statments there is no advantage for SPs here, in some other databases the SPs compiled into C or C++ but this isn&amp;#39;t the case in SQL Server 7.0/2000.&lt;/p&gt; &lt;p&gt;I have introuduced my view on the SP vs. Dynamic SQL i don&amp;#39;t see any benfit of SPs over the huge amount of productivity, performance that you will gain with dynamic SQL, the only benfit in peformance you will get it when using Managed SPs (SQL Server 2005) but for 0.7/2000 SPs isn&amp;#39;t the right choice for most of the scenarios.&lt;/p&gt; &lt;p&gt;Read more (diverse views):&lt;/p&gt; &lt;p&gt;- Frans Bouma&amp;#39;s &lt;a href="http://weblogs.asp.net/fbouma/archive/2003/11/18/38178.aspx"&gt;Stored procedures are bad, m&amp;#39;kay?&lt;/a&gt;&lt;/p&gt; &lt;p&gt;- Jeff Atwood&amp;#39;s &lt;a href="http://www.codinghorror.com/blog/archives/000292.html" target="_blank"&gt;Stored Procs vs. Ad-hoc&lt;/a&gt; , &lt;a href="http://www.codinghorror.com/blog/archives/000275.html" target="_blank"&gt;Give me parametrized SQL, or give me death&lt;/a&gt;&lt;/p&gt; &lt;p&gt;- Eric Wise&amp;#39;s &lt;a target="_blank"&gt;The Pragmatic Adhoc SQL vs Stored Procedures Discussion&lt;/a&gt;&lt;/p&gt; &lt;p&gt;- Rob Howard&amp;#39;s &lt;a href="http://weblogs.asp.net/rhoward/archive/2003/11/17/38095.aspx" target="_blank"&gt;Don&amp;#39;t use stored procedures yet? Must be suffering from NIHS (Not Invented Here Syndrome)&lt;/a&gt;&lt;/p&gt; &lt;p&gt;- Jeremy D. Miller&amp;#39;s &lt;a href="http://codebetter.com/blogs/jeremy.miller/archive/2006/05/25/145450.aspx" target="_blank"&gt;Why I do not use Stored Procedures&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Tiny Tip: is vs. as</title><link>http://bloggingabout.net/blogs/adelkhalil/archive/2007/10/08/tiny-tip-is-vs-as.aspx</link><pubDate>Mon, 08 Oct 2007 02:33:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:389842</guid><dc:creator>Adel Khalil</dc:creator><description>&lt;p&gt;Today&amp;#39;s tip&amp;nbsp;is a quick look at both not widely used C# operators and why prefer one to another..&lt;/p&gt;
&lt;p align="left"&gt;&lt;b&gt;Casting using is-operator:&lt;/b&gt;&amp;nbsp;&lt;/p&gt;
&lt;p align="left"&gt;if(p is Product) // CLR?: Could i cast this to product? &lt;/p&gt;
&lt;p align="left"&gt;{&lt;/p&gt;
&lt;p align="left"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Product x = (Product)p; // CLR again??: Could i cast this to Product?&lt;/p&gt;
&lt;p align="left"&gt;}&lt;/p&gt;
&lt;p align="left"&gt;This work but comes with performance cost so you better use the as-operator as follows:&lt;/p&gt;
&lt;p align="left"&gt;&lt;b&gt;Casting using as-operator:&lt;/b&gt;&lt;/p&gt;
&lt;p align="left"&gt;Product x = p as Product; // CLR?: Could i cast this to product? &lt;/p&gt;
&lt;p align="left"&gt;if(x!=null) &lt;/p&gt;
&lt;p align="left"&gt;{&lt;/p&gt;
&lt;p align="left"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // your logic here..&lt;/p&gt;
&lt;p align="left"&gt;}&lt;/p&gt;
&lt;p align="left"&gt;Here the CLR checks for type compatibility only one time and as-operator never throw an exception only the result will be null if it&amp;#39;s not type compatible.&lt;/p&gt;</description></item><item><title>Tiny Tools, Huge Benefits</title><link>http://bloggingabout.net/blogs/adelkhalil/archive/2007/09/12/tiny-tools-huge-benefits.aspx</link><pubDate>Wed, 12 Sep 2007 19:03:12 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:360116</guid><dc:creator>Adel Khalil</dc:creator><description>&lt;p&gt;Those are a subset of &lt;a href="http://www.hanselman.com/blog/ScottHanselmans2007UltimateDeveloperAndPowerUsersToolListForWindows.aspx" target="_blank"&gt;Hanselman&amp;#39;s tool list&lt;/a&gt;, those are very helpful during my daily job... so i thought i share with you.. to boost your productivity as well.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.albahari.com/queryexpress.html" target="_blank"&gt;Query Express&lt;/a&gt; -&amp;nbsp; A light weight Query&amp;nbsp;analyzer like application&amp;nbsp;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/" target="_blank"&gt;.NET Reflector&lt;/a&gt; - Amazing utility reflect over .NET Assemblies you can use it as code converter as well between number of .NET Languages.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.microsoft.com/technet/sysinternals/default.mspx" target="_blank"&gt;SysInternals Tools&lt;/a&gt; - Those are amazing now part of Microsoft.. Process Explorer, FileMon, RegMon and other goodies.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.iis.net/default.aspx?tabid=2&amp;amp;subtabid=29" target="_blank"&gt;IIS Diagnostic Tools&lt;/a&gt; -&amp;nbsp;Number of great tools allow debugging, tracing and other stuff as well.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=e59c3964-672d-4511-bb3e-" target="_blank"&gt;IE Developer Toolbar&lt;/a&gt; - A FireBug equivalent.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.getfirebug.com/" target="_blank"&gt;FireBug&lt;/a&gt; -&amp;nbsp;&amp;nbsp;Can&amp;#39;t debug without it... must have tool that looks underneath your page.&lt;/p&gt; &lt;p&gt;&lt;a href="http://memprofiler.com/" target="_blank"&gt;MemProfiler&lt;/a&gt; - Track memory leaks&lt;/p&gt; &lt;p&gt;if you have any tiny little goodies you use frequently please do share.&lt;/p&gt;</description></item><item><title>How fickle the SQL!</title><link>http://bloggingabout.net/blogs/egiardina/archive/2007/09/12/how-fickle-the-sql.aspx</link><pubDate>Wed, 12 Sep 2007 13:55:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:359950</guid><dc:creator>Richthofen</dc:creator><description>&lt;p&gt;So I was optimizing a query that displays a timetable of television programming. I&amp;#39;m working to try to optimize it because its currently taking 3-10 seconds per execution, which is less than optimal, considering that the query needs to be made 48 times per pageload, to load 48 timetables. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;The query looks something like this:&lt;/p&gt;SELECT * FROM TimeSlotsInADay CROSS JOIN (&lt;font color="#0000ff" size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; 
&lt;p&gt;SELECT&amp;nbsp; DISTINCT &lt;/font&gt;&lt;font size="2"&gt;dayofweek &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;FROM&lt;/font&gt;&lt;font size="2"&gt; Dashboard_TEST&lt;/font&gt;&lt;font color="#808080" size="2"&gt;.&lt;/font&gt;&lt;font size="2"&gt;dbo&lt;/font&gt;&lt;font color="#808080" size="2"&gt;.&lt;/font&gt;&lt;font size="2"&gt;broadcastDates&amp;nbsp;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;INNER JOIN ProgrammingData&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&amp;nbsp;Now normally you&amp;#39;d think that wouldn&amp;#39;t be too bad. Basically we have a list of timeslots, and we make an entry for every timeslot, every day. But it turns out, the bottleneck according to the Execution Planner was actually the cross join. So I ran the subquery and found out that the subquery was returning days in reverse order, while all my Indexes on those day fields were set to ASC order. So basically when the JOIN happened on programming data, because the list was reversed, the index scanning ended up being equivalent to a table scan. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;So I modified the list to ORDER BY on the subquery (which requires a TOP statement), so the Subquery now looks like:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;
&lt;p&gt;SELECT&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;DISTINCT&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;TOP&lt;/font&gt;&lt;font size="2"&gt; 7 dayofweek &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;FROM&lt;/font&gt;&lt;font size="2"&gt; Dashboard_TEST&lt;/font&gt;&lt;font color="#808080" size="2"&gt;.&lt;/font&gt;&lt;font size="2"&gt;dbo&lt;/font&gt;&lt;font color="#808080" size="2"&gt;.&lt;/font&gt;&lt;font size="2"&gt;broadcastDates &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;ORDER&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;BY&lt;/font&gt;&lt;font size="2"&gt; 1&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;And now the entire parent query executes in under a second. Hope this helps someone&lt;/font&gt;</description></item><item><title>In search for the fastest IList to IList&amp;lt;T&amp;gt; conversion</title><link>http://bloggingabout.net/blogs/ramon/archive/2007/06/18/in-search-for-the-fastest-ilist-to-ilist-lt-t-gt-conversion.aspx</link><pubDate>Sun, 17 Jun 2007 22:47:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:258316</guid><dc:creator>Ramon Smits</dc:creator><description>&lt;p&gt;I was yet again busy with a generic data layer. I like type safety as it provides compile time safety instead of run-time. The current released Db4o build (6.1) does not support type safe result list thus I had a need to convert these. My first approach was to just do a foreach like the following example:&lt;/p&gt;&lt;p&gt;Conversion one&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static System.Collections.Generic.IList&amp;lt;T&amp;gt; Convert1&amp;lt;T&amp;gt;(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Collections.IList source&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Collections.Generic.IList&amp;lt;T&amp;gt; result = new System.Collections.Generic.List&amp;lt;T&amp;gt;(source.Count);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (T o in source)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result.Add(o);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return result;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/p&gt;&lt;p&gt;But after I had this working I thought that this could be slow and that another solution was probably faster. I did a quick google search and ended up at a post of &lt;a href="http://weblogs.asp.net/bsimser/archive/2007/05/08/generic-list-converter-snippet.aspx"&gt;Bil Simser&lt;/a&gt;. There I saw some approaches in the comments but without additional information about its performance. So I made a little performance test where I tested not only the first example but also two others:&lt;/p&gt;&lt;p&gt;Conversion two&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static System.Collections.Generic.IList&amp;lt;T&amp;gt; Convert2&amp;lt;T&amp;gt;(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Collections.IList source&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Collections.ArrayList list = new System.Collections.ArrayList(source);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new List&amp;lt;T&amp;gt;(list.ToArray(typeof(T)) as T[]);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;br /&gt;Conversion three&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static System.Collections.Generic.IList&amp;lt;T&amp;gt; Convert3&amp;lt;T&amp;gt;(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Collections.IList source&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T[] output = new T[source.Count];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; source.CopyTo(output, 0);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return output;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;After creating an ArrayList I initialized it with 20.000.000 instances of my test class and then converted it to a type-safe IList&amp;lt;T&amp;gt;. After running it several times with no load on my system I got the following results:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Conversion one : ~2175ms&lt;br /&gt;Conversion two : ~ 884ms&lt;br /&gt;Conversion three : ~133ms&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;So my &amp;quot;vingerspitsgevoel&amp;quot; was right again! What amazes me is that the conversions timings are so far apart. At first I didn&amp;#39;t think that the second conversion would differ that much compared with the first but I think the .ToArray(..) method has CLR optimizations just as .CopyTo(..) method in the third example. The third conversion is more then 16 times faster then the first and even more then 6,5 times faster then the second.&lt;/p&gt;&lt;p&gt;The third conversion is even faster with much smaller arrays and lists (200.000 items). Then it is ~26 times faster then the first and ~7 times faster then the second conversion. I did this test on a Intel 3GHz D processor with 2GB of RAM on Windows XP Pro with the .net 2.0 framework.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;So if you were searching for (probably the fastest) ArrayList / IList to IList&amp;lt;T&amp;gt; conversion then you have found it. I immediately added the third conversion method to my personal framework code and I suggest that you do to after seeing these results.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Software RAID and virtualisation</title><link>http://bloggingabout.net/blogs/ramon/archive/2007/05/14/software-raid-and-virtualisation.aspx</link><pubDate>Mon, 14 May 2007 12:30:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:201088</guid><dc:creator>Ramon Smits</dc:creator><description>I have 3 harddrives in my home computer and today I though lets experiment with software RAID. So I first made some room on my drives and then created a 3 disk wide software RAID partition in Windows. After that I migrated my development virtual machine and started it. The damn thing is flying now! So if you have some room free on your partitions and don't want all your drives to be hardware RAID 0 because of failure then this is a good thing to do to have better virtualisation performance on your working machine.&lt;br&gt;&lt;br&gt;By the way, I'm using VMWare Server 6.0.3 as host.&lt;br&gt;</description></item><item><title>Improve Windows Forms performance</title><link>http://bloggingabout.net/blogs/adelkhalil/archive/2007/02/09/improve-windows-forms-performance.aspx</link><pubDate>Fri, 09 Feb 2007 14:52:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:110670</guid><dc:creator>Adel Khalil</dc:creator><description>&lt;p align="justify"&gt;&lt;font face="Verdana"&gt;This post is particularly for me as I always forgot those great tips and hard to find them back in MSDN Magazine or other resources, so I figure by putting them here will end up using them more also dear reader enjoy them too I'm sure you will find something you don't know or forgot a while ago.&lt;/font&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;p align="justify"&gt;&lt;font color="#ff8000" face="Verdana"&gt;&lt;strong&gt;fire your application faster&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;p align="justify"&gt;&lt;font face="Verdana"&gt;You can accomplish this by many ways starting with not populating the databoud controls in the load event directly instead have them on serrate thread so they don't block the UI while they linking to data source and rendering.&lt;/font&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;p align="justify"&gt;&lt;font face="Verdana"&gt;If you are using .NET 2.0 then you pleased with the new BackgroundWorker component that will delegate the work into background thread - &lt;em&gt;will talk in details about BackgroundWorker in other post&lt;/em&gt; .&lt;/font&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;p align="justify"&gt;&lt;font face="Verdana"&gt;Now the most important part which is will boost your application startup is using native image generator NGen which is available with .NET Framework SDK since version 1.1 at least.&lt;/font&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;p align="justify"&gt;&lt;font face="Verdana"&gt;couple of days ago I have attended session about improving application startup performance by NGen within &lt;a href="http://www.mdc07.com"&gt;MDC&lt;/a&gt;&lt;/font&gt; presented by Surupa Biswas Program Manager on CLR Team and with the demo she showed us the difference between launching Microsoft Expression Blend with and without NGen images like the difference between shooting a bullet and throwing it and this also speak of a seprate post.&lt;/p&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;p align="justify"&gt;&lt;font face="Verdana"&gt;&lt;strong&gt;&lt;font color="#ff8000"&gt;faster UI and Controls rendering&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt; &lt;/p&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;p align="justify"&gt;&lt;font face="Verdana"&gt;Always use BeginUpdate() and EndUpdate() to supress repaiting the controls while it's collection changing like the case of ListBox and ComboBox.&lt;/font&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;p align="justify"&gt;&lt;font face="Verdana"&gt;The neat trick i wouldn't thought of before by Milena Salman is when you hard code the data binding to a control is to assign the Control.ValueMemebr first then Control.DataSource couse assining the data source first will couse the control to repopulate.&lt;/font&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;p align="justify"&gt;&lt;font face="Verdana"&gt;Also notice that if you add controls at runtime, change or resize any existing controls will couas the parent control to fire Control.Layout event, so be sure to use SuspendLayout and ResumeLayout on the parent control when playing with the child controls.&lt;/font&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;p align="justify"&gt;&lt;font face="Verdana"&gt;&lt;strong&gt;&lt;font color="#ff8000"&gt;Don't lean much on garbage collector&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;p align="justify"&gt;&lt;font face="Verdana"&gt;Not becouse GC will let you down but for instant finalizing managed resourses within your code is less expensive by letting GC do the job also don't forget to use the using keyword with unmanaged resources, if you do finalize an unmanaged resource by yourself call the GC.SuppressFinalization to save a GC cycle.&lt;/font&gt;&lt;/p&gt;</description></item></channel></rss>