<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/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>Rico Mariani's Performance Tidbits : performance</title><link>http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx</link><description>Tags: performance</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Visual Studio 2010 Performance Part 3: A Technical Update</title><link>http://blogs.msdn.com/ricom/archive/2009/08/19/visual-studio-2010-performance-part-3-a-technical-update.aspx</link><pubDate>Wed, 19 Aug 2009 20:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9875795</guid><dc:creator>ricom</dc:creator><slash:comments>11</slash:comments><comments>http://blogs.msdn.com/ricom/comments/9875795.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=9875795</wfw:commentRss><description>&lt;P&gt;If I have any readers left out there, they might be interested to know what it is I’m up to this month.&amp;nbsp; It’s a very important something.&amp;nbsp; It’s... my vacation!&amp;nbsp; Ok, seriously, I am in fact on vacation and I’ll be out for the next few weeks mostly because I’ve been working really hard on VS performance for many months now and I’m kinda tired.&amp;nbsp; But, you still deserve a brief note from this tired camper, which I’ve been meaning to write for a while but something always came up – sorry about that :)&amp;nbsp; &lt;/P&gt;
&lt;P&gt;So, from my vacation, here’s a quick note.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is, more than usual, one of those postings where I wish I could be giving you a lot more detail but you’re just going to have to wait for that next beta for things to be fully revealed.&amp;nbsp; But I can say a few things, especially about technical issues, without getting into trouble.&amp;nbsp; Really, if you want to know about what &lt;EM&gt;features&lt;/EM&gt; need(ed) work, the easiest way to guess is to look at what people were complaining about.&amp;nbsp; It turns out they weren’t imagining things – go figure.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Technically, we found all sorts of fun issues. For instance, the product is a lot more multi-threaded than previous versions and in some cases synchronization between threads was less than great.&amp;nbsp; In some cases code designed to defer background work to keep the foreground responsive was actually slowing things down; in two cases I actually took out Sleeps, no joke! In some cases threads where synchronizing when they did not need to do so, destroying effective parallelism.&amp;nbsp; In other cases latent parallelism designed into the system wasn’t exploited at all, and rounding things out there were cases where there should have been parallelism in the design and it was totally absent.&amp;nbsp; That’s pretty much the full menu of problems you could have in that space.&lt;/P&gt;
&lt;P&gt;In the past, the IDE was just “flirting” with becoming a managed application, for some scenarios you could actually avoid the managed code entirely.&amp;nbsp; In Visual Studio 2010 you need only look at the profiles and observe how much time we spend in clr.dll to see that at this point Visual Studio is dominantly managed.&amp;nbsp; That brings a lot of benefits but also potential problems.&amp;nbsp; In many cases our first cut at communication between the managed and unmanaged pieces was pretty much terrible – all kinds of redundant copying of data, predominantly text, resulted in a lot of wasted CPU cycles and memory.&amp;nbsp; Many internal interfaces were redesigned to better cooperate between layers.&amp;nbsp; COM interop cases sometimes made this even trickier with &lt;A href="http://msdn.microsoft.com/en-us/library/aa302324.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa302324.aspx"&gt;CCW/RCW&lt;/A&gt; objects being created destroyed far too aggressively.&amp;nbsp; In some cases moving a nicer chunk of the work to the managed side helped a lot – kind of like writing stored procs for your database – good procedures mean fewer round trips and less data to move.&lt;/P&gt;
&lt;P&gt;Recently, we started taking a hard look at overall consumption and a lot of improvements are coming out of that work.&amp;nbsp; Memory is of course the main issue and there are three main sources of bad consumption that are getting targeted:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Managed images, especially ngen’d images.&amp;nbsp; It’s just super, &lt;EM&gt;super&lt;/EM&gt;, simple to take a dependency on a whole DLL in the managed world when all you need is a tiny slice of it.&amp;nbsp; This has the lovely property that others then build on those DLLs creating a great big tree of unneededness.&amp;nbsp; The good news is that examination can often lead to good refactoring opportunities which can save everyone a lot of memory.&amp;nbsp; This is for sure the #1 issue.&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;Unshared, unmanaged Heaps.&amp;nbsp; There are many low level pieces that manage their own memory and they inevitably do it with CreateHeap – joy.&amp;nbsp; Of course they make their own nice giant heap ready to go and then put about 22 bytes in it.&amp;nbsp;&amp;nbsp; Multiply that by all the components that think they need their own private heap and it gets unpleasant awfully quick.&amp;nbsp; Thankfully, this, too, is somewhat addressable.&amp;nbsp; Interestingly managed memory use hasn't been a big problem other than it's fair share of leaks (see next)&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;Memory leaks, pretty much universally, can be a problem in a product the size of VS.&amp;nbsp; No technology is immune but I sure like finding the managed ones better than the unmanaged – &lt;A href="http://blogs.msdn.com/ricom/archive/2004/12/10/279612.aspx" mce_href="http://blogs.msdn.com/ricom/archive/2004/12/10/279612.aspx"&gt;they literally can’t hide&lt;/A&gt;.&amp;nbsp; Other things that look like leaks but aren’t really – it’s important to use AddMemoryPressure/RemoveMemoryPressure to give the GC a chance to help you with your handle objects.&amp;nbsp; VS has a lot of those.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;I think you’re going to be pleased because we’ve been hitting most of the complaints squarely on the head.&amp;nbsp; From my chair, the product feels much, much, better.&lt;/P&gt;
&lt;P&gt;That’s it for now, I can’t wait to get another build into your hands!&lt;BR&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9875795" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/visual+studio/default.aspx">visual studio</category></item><item><title>Visual Studio: Why is there no 64 bit version?  (yet)</title><link>http://blogs.msdn.com/ricom/archive/2009/06/10/visual-studio-why-is-there-no-64-bit-version.aspx</link><pubDate>Thu, 11 Jun 2009 06:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9725681</guid><dc:creator>ricom</dc:creator><slash:comments>78</slash:comments><comments>http://blogs.msdn.com/ricom/comments/9725681.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=9725681</wfw:commentRss><description>&lt;P&gt;&lt;EM&gt;Disclaimer: This is yet another of my trademarked "approximately correct" discussions&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;From time to time customers or partners ask me about our plans to create a 64 bit version of Visual Studio. When is it coming? Why aren’t we making it a priority? Haven’t we noticed that 64 bit PC’s are very popular? Things like that. We just had an internal discussion about “the 64 bit issue” and so I thought I would elaborate a bit on that discussion for the blog-o-sphere.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;So why not 64 bit right away?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Well, there are several concerns with such an endeavor.&lt;/P&gt;
&lt;P&gt;First, from a performance perspective the pointers get larger, so data structures get larger, and the processor cache stays the same size. That basically results in a raw speed hit (your mileage may vary).&amp;nbsp; So you start in a hole and you have to dig yourself out of that hole by using the extra memory above 4G to your advantage.&amp;nbsp; In Visual Studio this can happen in some large solutions but I think a preferable thing to do is to just use less memory in the first place.&amp;nbsp; Many of VS’s algorithms are amenable to this.&amp;nbsp; Here’s an old article that discusses the performance issues at some length: &lt;A href="http://blogs.msdn.com/joshwil/archive/2006/07/18/670090.aspx" mce_href="http://blogs.msdn.com/joshwil/archive/2006/07/18/670090.aspx"&gt;http://blogs.msdn.com/joshwil/archive/2006/07/18/670090.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Secondly, from a cost perspective, probably the shortest path to porting Visual Studio to 64 bit is to port most of it to managed code incrementally and then port the rest.&amp;nbsp; The cost of a full port of that much native code is going to be quite high and of course all known extensions would break and we’d basically have to create a 64 bit ecosystem pretty much like you do for drivers.&amp;nbsp; Ouch.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[Clarification 6/11/09: The issue is this:&amp;nbsp; If all you wanted to do was move the code to 64 bit then yes the shortest path is to do a direct port.&amp;nbsp; But that’s never the case.&amp;nbsp; In practice porting has an opportunity cost, it competes with other desires.&amp;nbsp; So what happens is more like this:&amp;nbsp; you get teams that have&amp;nbsp;C++ code written for 32 bits and they say “I want to write feature X, if I port to managed I can do feature X plus other things more easily, that seems like a good investment” so they go to managed code for other reasons.&amp;nbsp; But now they also have a path to 64 bit.&amp;nbsp; What’s happening in practice is that more and more of the&amp;nbsp;Visual Studio&amp;nbsp;is becoming managed for reasons unrelated to bitness. Hence a sort of net-hybrid porting strategy over time.]&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;So, all things considered, my feeling is that the best place to run VS for this generation is in the 32 bit emulation mode of a 64 bit operating system; this doubles your available address space without taking the data-space hit and it gives you extra benefits associated with that 64 bit OS.&amp;nbsp; More on those benefits later.&lt;/P&gt;
&lt;P&gt;Having said that, I know there are customers that &lt;EM&gt;would&lt;/EM&gt; benefit from a 64 bit version but I actually think that amount of effort would be better spent in reducing the memory footprint of the IDE’s existing structures rather than doing a port.&amp;nbsp; There are many tradeoffs here and&amp;nbsp; the opportunity cost of the port is high.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Is it expensive because the code is old and of poor quality?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;It’s not really about the quality of the code – a lot of it is only a few releases old – as it is the &lt;I&gt;amount&lt;/I&gt; of code involved.&amp;nbsp; Visual Studio is huge and most of its packages wouldn’t benefit from 64 bit addressing but nearly all of it would benefit from using more lazy algorithms – the tendency to load too much about the current solution is a general problem which results in slowness even when there is enough memory to do the necessary work.&amp;nbsp; Adding more memory to facilitate doing even more work that we shouldn’t be doing in the first place tends to incent the wrong behavior.&amp;nbsp; I want to load less, not more.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Doesn’t being a 64 bit application save you all kinds of page faults and so forth?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;A 64 bit address space for the &lt;EM&gt;process &lt;/EM&gt;isn’t going to help you with page faults except in maybe indirect ways, and it will definitely hurt you in direct ways because your data is bigger.&amp;nbsp; In contrast a 64 bit &lt;EM&gt;operating system &lt;/EM&gt;could help you a lot!&amp;nbsp; If you’re running as a 32 bit app on a 64 bit OS then you get all of the 4G address space and all of that could be backed by physical memory (if you have the RAM) even without you using 64 bit pointers yourself.&amp;nbsp;&amp;nbsp; You’ll see potentially huge improvements related to the size of the disk cache (not in your address space) and the fact that your working set won’t need to be eroded in favor of other processes as much.&amp;nbsp; Transient components and data (like C++ compilers and their big .pch files) stay cached&amp;nbsp; in physical memory, but not in your address space.&amp;nbsp; 32 bit processes accrue all these benefits just as surely as 64 bit ones.&lt;/P&gt;
&lt;P&gt;In fact, the only direct benefit you get from having more address space for your process is that you can allocate more total memory, but if we’re talking about scenarios that already fit in 4G then making the pointers bigger could cause them to not fit and certainly will make them take more memory, never less.&amp;nbsp; If you don’t have abundant memory that growth&amp;nbsp;might make you page, and even if you do have the memory it will certainly make you miss the cache more often.&amp;nbsp; Remember the cache size does not grow in 64 bit mode but your data structures do.&amp;nbsp; Where you might get savings is if the bigger address space allowed you to have less fragmentation and more sharing.&amp;nbsp; But Vista+ &lt;A href="http://en.wikipedia.org/wiki/Address_space_layout_randomization" mce_href="http://en.wikipedia.org/wiki/Address_space_layout_randomization"&gt;auto-relocates&lt;/A&gt; images efficiently anyway for other reasons so this is less of a win.&amp;nbsp; You might also get benefits if the 64 bit instruction set is especially good for your application (e.g. if you do a ton of 64 bit math)&lt;/P&gt;
&lt;P&gt;So, the only way you’re going to see serious benefits is if you have scenarios that simply will not fit into 4G at all.&amp;nbsp; But, in Visual Studio anyway, when we don’t fit into 4G of memory I have never once found myself thinking “wow, System X needs more address space” I always think “wow, System X needs to go on a diet.”&lt;/P&gt;
&lt;P&gt;Your mileage may vary and you can of course imagine certain VS packages (such as a hypothetical data analytics debugging system) that might require staggering amounts of memory but those should be handled as special cases. And it is possible for us to do a hybrid plan with including some 64 bit slave processes.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I do think we might seem less cool because we’re 32 bit only but I think the right way to fight that battle is with good information, and a great product.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Then why did Office make the decision to go 64 bit?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This section is &lt;EM&gt;entirely recreational speculation &lt;/EM&gt;because I didn’t ask them (though frankly I should). But I think I can guess why. Maybe a kind reader can tell me how wrong I am :)&lt;/P&gt;
&lt;P&gt;First, some of the hardest porting issues aren’t about getting the code to run properly but are about making sure that the file formats the new code generates remain compatible with previous (and future) versions of those formats. Remember, the ported code now thinks it has 64 bit offsets in some data structures.&amp;nbsp; That compatibility could be expensive to achieve because these things find their way into subtle places – potentially any binary file format could have pointer-size issues. However, Office already did a pass on all its file formats to standardize them on compressed XML, so they cannot possibly have embedded pointers anymore. That’s a nice cost saver on the road to 64 bit products.&lt;/P&gt;
&lt;P&gt;Secondly, on the benefit side, there are customers out there that would love to load enormous datasets into Excel or Access and process them interactively. Now in Visual Studio I can look you in the face and say “even if your solution has more than 4G of files I shouldn’t have to load it all for you to build and refactor it” but that’s a much harder argument to make for say Excel.&lt;/P&gt;
&lt;P&gt;In Visual Studio if you needed to do a new feature like debugging of a giant analytics system that used a lot of memory I would say “make that analytics debugging package 64 bit, the rest can stay the way they are” but porting say half of Excel to 64 bits isn’t exactly practical.&lt;/P&gt;
&lt;P&gt;So the Office folks have different motivations and costs and therefore came to different conclusions -- the above are just my personal uninformed guesses as to why that might be the case.&lt;/P&gt;
&lt;P&gt;One thing is for sure though: I definitely think that the benefits of the 64 bit operating system are huge for everyone. Even if it was nothing more than using all that extra memory as a giant disk cache, just that can be fabulous, and you get a lot more than that!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9725681" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/ramblings/default.aspx">ramblings</category><category domain="http://blogs.msdn.com/ricom/archive/tags/design+advice/default.aspx">design advice</category><category domain="http://blogs.msdn.com/ricom/archive/tags/visual+studio/default.aspx">visual studio</category></item><item><title>Visual Studio 2010 Performance Part 2: Text Editor</title><link>http://blogs.msdn.com/ricom/archive/2009/06/05/visual-studio-2010-performance-part-2-text-editor.aspx</link><pubDate>Sat, 06 Jun 2009 06:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9702469</guid><dc:creator>ricom</dc:creator><slash:comments>17</slash:comments><comments>http://blogs.msdn.com/ricom/comments/9702469.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=9702469</wfw:commentRss><description>&lt;P&gt;&lt;A href="http://blogs.msdn.com/ricom/archive/2009/05/31/visual-studio-2010-performance-part-1-startup.aspx" mce_href="http://blogs.msdn.com/ricom/archive/2009/05/31/visual-studio-2010-performance-part-1-startup.aspx"&gt;Part 1&lt;/A&gt; of this series talked about the startup problems we face.&amp;nbsp; In Part 2, I want to talk about the editor. &lt;/P&gt;
&lt;P&gt;Many people have reported that editing with the new editor is slower. I’ve experienced the same thing myself so I certainly do not want to accuse people of hallucinating but I thought it might be interesting to understand why that might happen, especially since this new editor is supposed to be better than the old.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Why is this editor better and how is it better? &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I’m glad you asked :)&lt;/P&gt;
&lt;P&gt;It’s actually better in pretty much every editing way. The data structures associated with this new editor do not require complex locking algorithms for access, it delivers logical “micro-snapshots” of the editor buffer which do not change – it is a copy of the buffer at an instant in time. This is a fantastic situation if you are, for instance, a background compiler. Previously to get consistent snapshots the entire buffer had to be copied, potentially on every keystroke!&lt;/P&gt;
&lt;P&gt;And if that’s not enough, there’s a lot more. Another big tax on the editor is region management. Regions are used to track everything from bookmarks to breakpoints – and more. Those squiggles you see, those are all regions and there can be thousands of them. That is far beyond what the original editor design intended and those algorithms were starting to degenerate to quadratic behavior. You can see that yourself by noting that simply scrolling around at the end of large files in the old editor tended to get slower.&lt;/P&gt;
&lt;P&gt;Those are just two areas, but generally where the old editor had quadratic performance we were able to improve things to linear and in some places we were able to do even less work by being more careful about processing only visible segments of the text buffer. All goodness.&lt;/P&gt;
&lt;P&gt;So why is the thing slower if it’s so much better?&lt;/P&gt;
&lt;P&gt;Well let me elaborate a little more, but before I answer that directly, first let me tell you what things are almost certainly not the problem.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Not the problem #1: WPF&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;With the exception of some cases where we found that remoting WPF primitives over terminal server connections was slow, generally the WPF system is more than capable of keeping up with the editor. If you are seeing sluggish typing WPF is almost certainly not to blame.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Not the problem #2: Editor Primitive Operations.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The basic insert primitives are blazing fast, as low as a few microseconds even in very large files. If you’re seeing a problem, the chances that the text buffer is letting you down are slim to none.&lt;/P&gt;
&lt;P&gt;Ok, so, if it’s not those things, what is it? There’s two good bets.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Compatibility Shims&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The new editor is managed, and it has its own brand new managed interface. You can call it directly. However, there is lots of existing code that knows how to talk to the OLD editor and the old editor had a COM interface with its own particular API. We didn’t want to port all of the editor related code to the new editor’s managed interfaces – for several reasons but perhaps the most important is that there’s just so much of it. So we created a compatibility layer – shims – that allow old callers to use the new editor. That’s also important for our partners out there. That’s all fine and well but of course that means you’re going to be forced to use COM-interop where there was none before and of course those shims have to emulate the old editors behavior even when that wasn’t exactly the fastest choice in the west.&lt;/P&gt;
&lt;P&gt;So sometimes improving editor responsiveness has meant converting more code to the direct interface and thereby avoiding the shims. The trick here is to make sure you convert the code that needs converting rather than going crazy trying to convert all of it in one go.&lt;/P&gt;
&lt;P&gt;OK but who are all these users? What are we talking about here?&lt;/P&gt;
&lt;P&gt;That brings us to the second point. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Event Listeners&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Another reason why the editor can get bogged down is that various clients can register for notifications of interesting events. This is actually very popular (understatement) and important things like the language’s intellisense services want to be notified of various things going on in the buffer. Now it turns out that the actual editing primitives are so fast that the bulk of the cost of doing edits is actually in these various event processors. Sometimes because they are using shims, sometimes just because they are being over-aggressive in subscribing to things. Sometimes because they have their own personal problems that are only incidentally related to editing.&lt;/P&gt;
&lt;P&gt;One way that you can see the difference in the root cause of editing yourself is to try your editing operations in a file named ‘foo.txt’ rather than ‘foo.cs’ or ‘foo.vb’ or whatever the case may be. This will disable many of the event listeners and give you a truer feel for what the editor itself is doing. Even that isn’t perfect because of course there are still listeners for bookmarks, and other kinds of things that are applicable to even plain text files.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;What are we doing about it?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Well I think I’ve already alluded to it. Make better use of the underlying editor primitives. Move more things off the shims where the cost is high. Reduce the cost and number of listeners generally. And of course make sure that our text and region management primitives stay nice and fast.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;What can you do?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If you see the editor behaving dumbly, enter bugs. They really help!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9702469" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/visual+studio/default.aspx">visual studio</category></item><item><title>Visual Studio 2010 Performance Part 1: Startup</title><link>http://blogs.msdn.com/ricom/archive/2009/05/31/visual-studio-2010-performance-part-1-startup.aspx</link><pubDate>Sun, 31 May 2009 10:46:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9667714</guid><dc:creator>ricom</dc:creator><slash:comments>31</slash:comments><comments>http://blogs.msdn.com/ricom/comments/9667714.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=9667714</wfw:commentRss><description>&lt;p&gt;I want to start by thanking everyone that has commented on the Beta (by posting their thoughts here or elsewhere) for doing so. Please keep those comments coming! They have a great impact on the senior leadership here and they are excellent rallying points for all the teams. They really do make a difference!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/jasonz"&gt;Jason&lt;/a&gt; has come right out and said he’s tapped me to work basically full-time on performance work for Visual Studio until we’re done; that’s understating the situation if that’s possible. I think I had already tapped myself before he tapped me and at this point I’m a bit of a lightning rod for performance issues in the product. I think that’s a good thing. :)&lt;/p&gt;  &lt;p&gt;Just like I did back when I was writing about performance problems for the CLR I’m going to talk about things as candidly as possible. Including the bad parts.&amp;#160; While I do that I want you to keep in mind that I write the truth as I see it and I often have to write what I like to called “approximately correct” articles, mostly in the interest of brevity; being more than approximately correct causes the word count to skyrocket. I won’t keep reminding you that I’m doing this but it’s been a while so I thought maybe a refresher would be good.&lt;/p&gt;  &lt;p&gt;Lastly, I try to use affirmative language about what I’m doing or what I think the teams are doing but I generally avoid making promises even when any idiot could see that we would be colossally stupid to do other than what I am discussing or perhaps what one of my readers has suggested. I avoid it because there are many teams involved, with many choices at hand, and many opportunities for things to go badly despite the best laid plans. So I just try not to go there. I’m sorry about that.&lt;/p&gt;  &lt;p&gt;OK enough disclaimers already.&lt;/p&gt;  &lt;p&gt;This is, what I hope is the first in a series of articles about performance related happenings in Visual Studio. I hope you find them helpful and interesting. I’m going to start at the start – and that’s Visual Studio startup.&lt;/p&gt;  &lt;p&gt;I’ve actually talked about Startup several times over the last few years. That’s because I want people to understand that of all the things that are going to get better, startup is not one of them. Yup, that’s right; I gave up at the start. No kidding. No pretending. It’s going to start slower. Sorry.&lt;/p&gt;  &lt;p&gt;But wait; don’t give up on me yet!&lt;/p&gt;  &lt;p&gt;We decided to make some investments in better display technology in this release and for the future; that meant loading WPF at startup. We decided to have a superior extensibility model for our future and that meant MEF at startup. And in general we went from having no managed code at all at startup to having a LOT of managed code at startup. That stuff isn’t free, and nobody knows it better than me. [I rhymed]&lt;/p&gt;  &lt;p&gt;In some cases I’ve seen as much as 75% of our time in current startup scenarios actually in clr.dll – incredible isn’t it? In VS2008 that was 0%! But even though that’s technically true, it’s also a bit of a lie… &lt;/p&gt;  &lt;p&gt;In VS2008 you could start the IDE without bringing in the managed stack and you could avoid allocating say the GC heaps and whatnot but it’s an illusion. For the most part, if you did anything real you would find that you had paid that cost very shortly after startup and almost certainly before you were “Ready to Work.” That experience is the one that I wanted teams to focus on in this release: don’t prioritize start to empty, prioritize start to ready.&lt;/p&gt;  &lt;p&gt;Now in start to ready we are in much better shape. There were many, what shall I call them, hmm, known weaknesses? There were known weaknesses in the startup path from initial boot, to opening your solution, to opening an editor. I’ve talked about many of these in the past. Consumption in the project system and language systems was high. Editor related algorithms were costly, quadratic complexity or worse in some important cases. That means there is opportunity there. So we keep fighting to create an overall experience that you’ll find better, one that will make you more productive, even though we’re giving ground on some parts of the experience.&lt;/p&gt;  &lt;p&gt;Now if you think we’re going to open a small foo.txt file as fast as say notepad… well… I’m sorry, we’re not going to do that. We never had a chance. Other editors are making other kinds of tradeoffs and are much better positioned to give a great experience in that case. But if you want to open say a medium sized solution now we’ve got a fighting chance to offer real advantages.&lt;/p&gt;  &lt;p&gt;Now maybe that sounds great, or maybe it doesn’t, but in any case the trouble with focusing on end-to-end productivity is that even if you do make the “on average” experience better you still run the risk of having some painful parts be worse than they used to be and those parts just totally ruin the experience for customers. We’re trying to be mindful of that. Take for instance our friend the Add References Dialog, I don’t think anyone is thinking about how “on average the product is faster” when they are waiting for that thing to come up.&amp;#160; I’m sure not.&lt;/p&gt;  &lt;p&gt;So this article is supposed to be about Startup, what are we doing to make it better? Well, there are some very specific things that we think are going to help. These ones represent maybe 25% of the total cost of startup (to empty) in the beta build.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;We use WPF toolbars and the toolbar layout code in the beta is naïve. That needs to get better (I like what I see so far)&lt;/li&gt;    &lt;li&gt;WPF does drawing in the background with a render thread; that thread sometimes has to synchronize with the main UI thread. Some of those look like they can be removed.&lt;/li&gt;    &lt;li&gt;The way we create the toolbars is more complicated than it needs to be. We can get the exact same result using fewer UIElements with some style and code changes&lt;/li&gt;    &lt;li&gt;We have a hot list of methods in the CLR that are important in our startup, we’re hoping some of those can be improved, and also that those improvements aren’t unique to Visual Studio&lt;/li&gt;    &lt;li&gt;A classic thing that happens in every Visual Studio release is that we go through a period where we have bunches of code (often VS packages) that are getting loaded at startup that to not need to get loaded at startup. We’re making a list and checking it twice.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The best thing about most of these changes is that they actually help many scenarios (e.g. almost every time we change modes) not just startup.&lt;/p&gt;  &lt;p&gt;These things will help Start to Empty to be as good as it can be.&amp;#160; I’m going to talk about Start to Ready more in a later posting.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9667714" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/visual+studio/default.aspx">visual studio</category></item><item><title>Visual Studio 10 -- Your Performance Feedback plus Beta 1</title><link>http://blogs.msdn.com/ricom/archive/2009/05/20/visual-studio-10-your-performance-feedback-plus-beta-1.aspx</link><pubDate>Wed, 20 May 2009 23:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9632816</guid><dc:creator>ricom</dc:creator><slash:comments>48</slash:comments><comments>http://blogs.msdn.com/ricom/comments/9632816.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=9632816</wfw:commentRss><description>&lt;P&gt;At Microsoft you can't say you're excited about anything you have to say that you're "super excited".&amp;nbsp; I don't know why that's &lt;A href="http://haacked.com/archive/2007/10/26/drinking-from-the-firehose.aspx" mce_href="http://haacked.com/archive/2007/10/26/drinking-from-the-firehose.aspx"&gt;just the way it is&lt;/A&gt;.&amp;nbsp; So, I'm happy to say that I'm super excited about the release of Beta 1 and I encourage you all to visit &lt;A href="http://blogs.msdn.com/jasonz" mce_href="http://blogs.msdn.com/jasonz"&gt;Jason's blog&lt;/A&gt; (again) to see screen-shots and get the download info.&amp;nbsp; And more importantly to actually try it out and give us feedback.&amp;nbsp; Your feedback so far has made a big difference and it will continue to do so, if only because it gives me ammunition with which to beat up -- err, I mean, educate -- executives here in DevDiv :)&lt;/P&gt;
&lt;P&gt;Right now we're at a stage where it's crucial to lock in the gains we have and make sure everything we do is only making things better.&amp;nbsp; That means detecting any performance regressions builds, day to day, is paramount.&amp;nbsp; Now I have some general advice about that, I've been trying to teach for year that consumption metrics are very important and often a better way to track performance even though they aren't directly what your customers care about -- &lt;A href="http://blogs.msdn.com/ricom/archive/2004/03/15/89934.aspx" mce_href="http://blogs.msdn.com/ricom/archive/2004/03/15/89934.aspx"&gt;this old article&lt;/A&gt; discussed that a bit with regard to memory use.&amp;nbsp; For regression detection I think it's even more important to focus on consumption rather than elapsed time.&amp;nbsp; I was trying to explain this yesterday and I came up with this pithy quote:&lt;/P&gt;
&lt;P&gt;"Trying to control your performance by measuring only elapsed time is kind of like trying to control your weight by measuring how much time you spend eating."&lt;/P&gt;
&lt;P&gt;It's -- dare I say it -- super-important to use a variety of metrics and watch your overall consumption because too many extraneous, impossible to control, variables affect elapsed time run-to-run.&lt;/P&gt;
&lt;P&gt;Now moving on to some feedback, I first wanted to thank everyone that wrote in response to &lt;A href="http://blogs.msdn.com/ricom/archive/2009/05/14/visual-studio-working-on-performance.aspx" mce_href="http://blogs.msdn.com/ricom/archive/2009/05/14/visual-studio-working-on-performance.aspx"&gt;my last posting&lt;/A&gt; and encourage you to keep giving feedback.&amp;nbsp; There were a few common themes that I wanted to discuss in detail.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Add/Remove References Dialog&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I've personally made a pitch to make this better and I expect to see it getting attention.&amp;nbsp; At the very least I want the default tab changed to be a faster one.&amp;nbsp; This dialog is universally despised and got more negative comments than any other feature.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Unit Tests, especially batch runs&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;That team is looking at larger run cases and trying to optimize the amount of data gathered versus the run speed.&amp;nbsp; Hope to see some nice gains there.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;General Typing speed (C#, VB, C++)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I've been looking at that scenario personally and with a lot of help from our languages team.&amp;nbsp; There are many factors that affect speed, not the least of which is the language service that provides intellisense but there are other important factors like the raw speed of the new editor, the amount of outlining, etc..&amp;nbsp;&amp;nbsp;&amp;nbsp; We've made big improvements here since the PDC but we're still not happy with it so we're pushing for even more gains before we ship.&lt;/P&gt;
&lt;P&gt;"Cat" commented that "I'd hazard that partial class support was added to C# just because of this problem."&amp;nbsp; I can assure you that that was not the case.&amp;nbsp; Partial classes were added for several reasons but I would say the main one was to allow better separation of designer generated code vs. human generated code. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Silverlight and WPF tooling&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Some things are already better because WPF is loaded first but other things have suffered because there were many changes in that tool suite and it's still in need of performance work.&amp;nbsp; I think you'll find Beta1 is better than the PDC but I expect you'll still find some areas wanting.&amp;nbsp; Typing speed in XAML files was something that we were especially wanting to look at.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Help &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I really wish we could be showing you more of this in the beta it was so close to being ready but the internal version just wasn't quite there.&amp;nbsp;&amp;nbsp; We've totally overhauled how it works, the core storage is a much simpler standards-based solution, the reader is much simplified, the first load should be vastly faster, installing new help and getting updates will be vastly faster.&amp;nbsp; There's a bit of information on &lt;A href="http://blogs.msdn.com/aprilr/archive/2009/05/18/early-parts-of-help3-come-to-life-in-visual-studio-2010-beta-1.aspx" mce_href="http://blogs.msdn.com/aprilr/archive/2009/05/18/early-parts-of-help3-come-to-life-in-visual-studio-2010-beta-1.aspx"&gt;April's blog&lt;/A&gt; and in particular you can try out the lo-band version of online help (which I think is a lot closer to what our final look will be).&amp;nbsp; I've been very involved in this effort and I'm especially looking forward to getting the new help technology into more people's hands.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Copy Local&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Patrick brought up an &lt;A href="http://codebetter.com/blogs/patricksmacchia/archive/2009/01/11/lessons-learned-from-the-nunit-code-base.aspx" mce_href="http://codebetter.com/blogs/patricksmacchia/archive/2009/01/11/lessons-learned-from-the-nunit-code-base.aspx"&gt;opportunity to improve Copy Local&lt;/A&gt; based on his experience.&amp;nbsp; I'm hoping we can move that solution to use NTFS hard links when they are available to provide that functionality without moving so many bits.&amp;nbsp; I noticed the same activity in some of our test cases -- the problem is of course not unique to NUnit.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;WPF Optimizations&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Personally I'm focused on WPF changes that will help Visual Studio -- like for instance improvements in how Toolbars are arranged, and general synchronization between the UI thread and the rendering thread.&amp;nbsp; Some of this work translates to gains that are helpful universally, some not so much.&amp;nbsp; But I am encouraging the WPF team to read this posting and that should help too.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Solution/Project management&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Lots of work is happening in this space.&amp;nbsp; Customers sometimes have huge solutions and they can't afford to wait for us to load everything before they are allowed to start working.&amp;nbsp; I'm actively driving improvements in that area. I wish I could promise more but, I'm not especially merciful, I can promise that :)&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Specific Bugs&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;There were several bug reports already in the feedback, I will do my best to get the right people to look at this stuff.&amp;nbsp; A lot of times all I can do is shrug -- it's a big product, I know a lot of it but, even after 20 years, I don't know it all.&lt;/P&gt;
&lt;P&gt;I'm sorry if I didn't respond to your particular comment, I did read every word but this posting is already too long.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9632816" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/visual+studio/default.aspx">visual studio</category></item><item><title>Visual Studio -- working on performance</title><link>http://blogs.msdn.com/ricom/archive/2009/05/14/visual-studio-working-on-performance.aspx</link><pubDate>Thu, 14 May 2009 20:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9616690</guid><dc:creator>ricom</dc:creator><slash:comments>35</slash:comments><comments>http://blogs.msdn.com/ricom/comments/9616690.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=9616690</wfw:commentRss><description>&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;&lt;A href="http://blogs.msdn.com/jasonz" mce_href="http://blogs.msdn.com/jasonz"&gt;Jason&lt;/A&gt; has a new posting on the progress of Visual Studio and I wanted to chime in myself.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Some people have been wondering what I’ve been up to… I think you’ll be happy to hear that about 2 months ago I put down a bunch of my long term planning&amp;nbsp;responsibilities so that I could work on Visual Studio performance directly.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Woo hoo! &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;So performance work: what kind of work?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Well the most important thing I’ve been doing is helping people in VS to understand where the problems are, and how to make directed improvements that get locked in. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;I’ve been doing lots of training, I’ve been creating custom analysis tools for studying VS performance problems, and I’ve also been yelling at a lot of people and just generally making all kinds of friends in my division.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;:)&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;During these last weeks we’ve made a lot of progress, I’m sure you’re going to feel the product is a lot snappier than the builds we provided at the PDC.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;But of course I’m never satisfied – there are even more wins coming later.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I worked with many different teams to help us with our startup, with UI transitions, with memory usage, with threading issues – especially with how WPF and our main thread synchronize.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This very morning I’m busy reviewing goals for every major group in Visual Studio and we’re working hard to create a great experience.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I’m especially happy with the changes that will benefit many applications (like some of the ones that are finding their way into WPF, or interop)&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;So, especially for the next big push before release, performance will be a very high priority for Visual Studio – I’m going to be very pleasantly busy.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;What does this all mean to you?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;My blog is now a great place to give your feedback, especially on the Beta when it comes out.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Tell me what is hurting you the most, many people will be watching, including me, and we still have time to get attention on key problems.&amp;nbsp; I'd love to hear about it.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9616690" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/visual+studio/default.aspx">visual studio</category></item><item><title>Performance Advice, Southern Style </title><link>http://blogs.msdn.com/ricom/archive/2008/11/28/performance-advice-southern-style.aspx</link><pubDate>Sat, 29 Nov 2008 00:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9153447</guid><dc:creator>ricom</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/ricom/comments/9153447.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=9153447</wfw:commentRss><description>&lt;P&gt;While I was at PDC2008 I was introduced to Keith and Woody -- pretty soon there was a microphone in front of me and we were doing a podcast.&amp;nbsp; Now I already liked these guys but when they used a picture of me from about 1998 I really liked them a lot more.&amp;nbsp; I wish I still looked like that :).&lt;/P&gt;
&lt;P&gt;And the interview was pretty fun too. ;)&lt;/P&gt;
&lt;P&gt;Keith, Woody,&amp;nbsp;thanks for having me.&lt;/P&gt;
&lt;P&gt;You guys can check it out here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="http://deepfriedbytes.com/podcast/episode-21-talking-performance-with-performance-preacher-rico-mariani/" mce_href="http://deepfriedbytes.com/podcast/episode-21-talking-performance-with-performance-preacher-rico-mariani/"&gt;http://deepfriedbytes.com/podcast/episode-21-talking-performance-with-performance-preacher-rico-mariani/&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9153447" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/design+advice/default.aspx">design advice</category><category domain="http://blogs.msdn.com/ricom/archive/tags/recommendations/default.aspx">recommendations</category></item><item><title>Performance by Design at PDC2008!</title><link>http://blogs.msdn.com/ricom/archive/2008/09/12/performance-by-design-at-pdc2008.aspx</link><pubDate>Fri, 12 Sep 2008 22:48:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8948024</guid><dc:creator>ricom</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/ricom/comments/8948024.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=8948024</wfw:commentRss><description>I'm happy to announce that I will be at PDC2008 (and I will work the booths until I can't speak) but in particular I'll be kicking off this precon event with my longtime colleagues Mark, Joe, and Vance.   &lt;p&gt;Come on out, I'd love to meet some of my readers!&lt;/p&gt;  &lt;h4&gt;&lt;a href="http://www.microsoftpdc.com/Agenda/Preconference.aspx#performance-by-design-using-the-net-framework"&gt;Performance by Design: Using the .NET Framework&lt;/a&gt;&lt;/h4&gt;  &lt;h6&gt;Presenters: &lt;a href="http://blogs.msdn.com/ddperf/"&gt;Mark Friedman&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/ddperf/"&gt;Joe Hellerstein&lt;/a&gt;, Rico Mariani, &lt;a href="http://blogs.msdn.com/vancem/"&gt;Vance Morrison&lt;/a&gt; &lt;/h6&gt;  &lt;p&gt;The.NET Framework offers developers a dizzying array of design choices for building applications, whether they are client or server-side applications. These choices can greatly impact the performance and scalability of your application. This session highlights best practices in application architecture, testing, tools, and techniques for building responsive and highly scalable applications using the .NET Framework. More than just practical advice, this session focuses on proven techniques for building high quality applications. You will also learn what measurement data is available from the CLR and the OS and will understand how to leverage this data to optimize your application&amp;#8217;s performance. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8948024" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/recommendations/default.aspx">recommendations</category></item><item><title>Is Performance a "functional" requirement?</title><link>http://blogs.msdn.com/ricom/archive/2008/08/27/is-performance-a-functional-requirement.aspx</link><pubDate>Wed, 27 Aug 2008 19:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8900780</guid><dc:creator>ricom</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/ricom/comments/8900780.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=8900780</wfw:commentRss><description>&lt;P&gt;We had an internal thread on this yesterday, maybe I was a little too glib but here is what I had to say about the topic [edited so it can be read standalone]&lt;/P&gt;
&lt;P&gt;The original question, “Is performance a functional requirement” is highly unexciting for me.&amp;nbsp; However the revised question, “What is the best way to capture performance requirements” is profoundly interesting.&amp;nbsp; It is precisely the (anti-)correlations between attainable functionality and level of responsiveness that sometimes makes for the very best engineering work.&amp;nbsp; How do you capture all this?&amp;nbsp; Sometimes pervasively. I would argue that pervasively is in fact the only answer that works in non-trivial cases.&amp;nbsp; And this is not limited to performance as the quality metric of interest – it applies to any quality that is not going to be trivially achieved.&lt;/P&gt;
&lt;P&gt;The nomenclature to me is uninteresting except to the extent that it assists designers and implementers in capturing&amp;nbsp; and understanding the various kinds of requirements – i.e. I know where to put them, I know where to find them, I know that I got them all, because I am, literally, on a first name basis with all the requirement types.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I don’t want to trivialize that aspect, but, beyond that, meh, whatever… functional schmuntional, I don’t care what you call it, just do it :)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8900780" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/ramblings/default.aspx">ramblings</category></item><item><title>Linq Compiled Queries Q &amp; A</title><link>http://blogs.msdn.com/ricom/archive/2008/08/25/linq-compiled-queries-q-a.aspx</link><pubDate>Mon, 25 Aug 2008 22:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8894803</guid><dc:creator>ricom</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/ricom/comments/8894803.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=8894803</wfw:commentRss><description>&lt;P&gt;I did a series of postings on &lt;A href="http://blogs.msdn.com/ricom/archive/2007/06/22/dlinq-linq-to-sql-performance-part-1.aspx" mce_href="http://blogs.msdn.com/ricom/archive/2007/06/22/dlinq-linq-to-sql-performance-part-1.aspx"&gt;Linq Compiled Queries&lt;/A&gt; last year, I recently got some questions on those postings that I thought would be of general interest.&lt;/P&gt;
&lt;P&gt;Q1:&lt;/P&gt;
&lt;P&gt;Why use the 'new' keyword in this snippet?&lt;/P&gt;
&lt;P&gt;var q = from o in nw.Orders &lt;BR&gt;select &lt;STRONG&gt;new &lt;/STRONG&gt;{o.everything …};&lt;/P&gt;
&lt;P&gt;A:&lt;/P&gt;
&lt;P&gt;If you did just :&lt;/P&gt;
&lt;P&gt;var q = from o in nw.Orders &lt;BR&gt;select o;&lt;/P&gt;
&lt;P&gt;You're getting editable orders. Linq then has to track them in case you change them and want to submit the changes. If you use new effectively you're making a copy of the orders that is not going to be change tracked. That's faster for read only cases. The other thing you can do is mark the query context as read-only and then you get the same effect.&amp;nbsp; When I wrote that test case, that feature wasn't available yet so I used &lt;STRONG&gt;new &lt;/STRONG&gt;to simulate it.&lt;/P&gt;
&lt;P&gt;Q2:&amp;nbsp; &lt;/P&gt;
&lt;P&gt;What do you mean when you say that linq will 'Create custom methods that bind the data perfectly' ?&lt;/P&gt;
&lt;P&gt;A:&lt;/P&gt;
&lt;P&gt;Whenever you use linq to sql to read data from a database it has to do two important things for you. The first is convert your Linq query into SQL. The second is to make a method that takes the stream of data that comes back from the database and converts it into the managed objects you required. That's the data-binding step. Linq creates the necessary methods automatically, and it makes the perfect code for doing this.&lt;/P&gt;
&lt;P&gt;Q3:&lt;/P&gt;
&lt;P&gt;How did Linq to SQL beat your ADO.Net code for insert times.&amp;nbsp; Shouldn't a tie be the best possible result?&lt;/P&gt;
&lt;P&gt;A:&lt;/P&gt;
&lt;P&gt;The SQL I used in my test case was pretty much the standard simplest SQL you would use for such a job. The automatically generated SQL from Linq was better than what I wrote by hand because they had parameterized the insert statements which I never bothered to do. Had I changed my SQL to what they created it would have been a tie. This is kind of like when the C++ compiler finds a machine code pattern that is better than what you would have written doing it by hand because it did something you don't usually bother doing with hand tuned machine code. But you *could* replace what you wrote with what the compiler generated.&lt;/P&gt;
&lt;P&gt;Q4: &lt;/P&gt;
&lt;P&gt;What are the downsides to precompiled queries?&lt;/P&gt;
&lt;P&gt;A:&lt;/P&gt;
&lt;P&gt;There is no penalty to precompiling (&lt;A href="http://blogs.msdn.com/ricom/archive/2008/01/11/performance-quiz-13-linq-to-sql-compiled-queries-cost.aspx" mce_href="http://blogs.msdn.com/ricom/archive/2008/01/11/performance-quiz-13-linq-to-sql-compiled-queries-cost.aspx"&gt;see Quiz #13&lt;/A&gt;). The only way you might lose performance is if you precompile a zillion queries and then hardly use them at all -- you'd be wasting a lot of memory for no good reason.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;But measure :)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8894803" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/design+advice/default.aspx">design advice</category><category domain="http://blogs.msdn.com/ricom/archive/tags/databases/default.aspx">databases</category></item><item><title>Just another day in the perf lab</title><link>http://blogs.msdn.com/ricom/archive/2008/06/18/just-another-day-in-the-perf-lab.aspx</link><pubDate>Thu, 19 Jun 2008 00:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8618561</guid><dc:creator>ricom</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/ricom/comments/8618561.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=8618561</wfw:commentRss><description>&lt;P&gt;Even though I've been doing general architecture work on Visual Studio for nearly a year now, my friends in DDPERF are still plugging away on performance problems and finding some interesting results.&lt;/P&gt;
&lt;P&gt;This &lt;A href="http://blogs.msdn.com/ddperf/archive/2008/06/18/lessons-from-the-test-lab-investigating-a-pleasant-surprise.aspx" mce_href="http://blogs.msdn.com/ddperf/archive/2008/06/18/lessons-from-the-test-lab-investigating-a-pleasant-surprise.aspx"&gt;most recent thread&lt;/A&gt; is very interesting because it shows yet another example of how the consequences of hardware changes can be subtle and very hard to predict.&lt;/P&gt;
&lt;P&gt;Just today I was working with &lt;A href="http://channel9.msdn.com/posts/funkyonex/Performance-Improvements-in-Visual-Studio-2008/" mce_href="http://channel9.msdn.com/posts/funkyonex/Performance-Improvements-in-Visual-Studio-2008/"&gt;Cameron McColl&lt;/A&gt; again-- this time we were trying to understand why a particular benchmark was sometimes mysteriously slower than normal for no apparent reason.&amp;nbsp; To our delight we found (well, mostly Cameron, I was the "consultant" &amp;lt;grin&amp;gt;) that the problem was in how the timing was being triggered and so the bulk of the variability seems to be measurement error and not actual test variability.&amp;nbsp; But to our chagrin, the slower time seems to more accurately reflect reality.&amp;nbsp; Well at least now we know.&lt;/P&gt;
&lt;P&gt;How are these things related? &lt;/P&gt;
&lt;P&gt;They remind us all that it's very important to track down anomalies in your reported results because otherwise you have little understanding of why you are making things faster, what works and what doesn't.&lt;/P&gt;
&lt;P&gt;In the words of Alastor "Mad Eye" Moody:&amp;nbsp; "Constant Vigilance!"&lt;/P&gt;
&lt;P&gt;P.S. If you're looking for the further adventures of the devdiv perf team, you could do worse than subscribe to &lt;A href="http://blogs.msdn.com/ddperf" mce_href="http://blogs.msdn.com/ddperf"&gt;their blog&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8618561" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/recommendations/default.aspx">recommendations</category></item><item><title>Shutdown Is No Time For Spring Cleaning</title><link>http://blogs.msdn.com/ricom/archive/2008/05/12/shutdown-is-no-time-for-spring-cleaning.aspx</link><pubDate>Mon, 12 May 2008 22:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8496478</guid><dc:creator>ricom</dc:creator><slash:comments>19</slash:comments><comments>http://blogs.msdn.com/ricom/comments/8496478.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=8496478</wfw:commentRss><description>&lt;P&gt;I think my current performance pet peeve is shutdown.&amp;nbsp; Assorted flavors of it, they all seem to have the same kind of problem.&amp;nbsp; Sometimes we're stuck with it... but maybe we shouldn't be?&lt;/P&gt;
&lt;P&gt;This is one time when our basic training, which normally I love so much, tends to let us down.&amp;nbsp; We were all taught to clean up our own messes -- programming wise that means freeing your resources after you are done with them.&amp;nbsp; But this backfires in the shutdown case.&lt;/P&gt;
&lt;P&gt;Many times I watch as I hit the [X] close button on some application and my poor computer starts to swap as the application goes about paging in vast amounts of its code and then dutifully walking all its data structures--&amp;nbsp;more paging -- and giving them back to the operating system.&amp;nbsp; My reaction to this in a word:&amp;nbsp; ACK!!!!&lt;/P&gt;
&lt;P&gt;When your application is ordered to shutdown the last thing you should do is enumerate every piece of memory you have ever allocated and systematically give them back to the operating system.&amp;nbsp; Your program has a death sentence, and soon your resources are going back to the operating system whether you like it or not:&amp;nbsp; what you must do&amp;nbsp; is look at the minimum possible amount of memory necessary to get to a nice safe stable state and then exit as quickly as possible.&amp;nbsp; Abandoning your memory like this gives the operating system the best chance to get your process unloaded while swapping in the least amount of memory and causing the least impact to the systems disk and memory caches.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;In short, shutdown is no time for spring cleaning.&lt;/P&gt;
&lt;P&gt;And why all this cleaning anyway?&amp;nbsp; Many people report that they have all these important resources that need flushing and so forth.&amp;nbsp; They couldn't possibly get to a safe state without considerable work but usually that in itself is symptomatic of assorted problems.&amp;nbsp; Any application that has important data to manage almost certainly needs to be tolerant of power-failure and if that's the case when the user makes important edits they likely should be automatically saved to a durable location.&amp;nbsp; In fact at any given moment, probably only a few seconds worth of data should be at risk.&amp;nbsp; If your application has been idle for any length of time it should be fully saved -- and even if the user hasn't chosen to save their work it's still effectively saved somewhere so that you could restore in the current "dirty" state.&lt;/P&gt;
&lt;P&gt;So if you have to do all this work to be resilient to power failures, then take advantage of that logic to simplify your shutdown paths.&amp;nbsp; Your users will thank you.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8496478" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category></item><item><title>Computer Measurement Group offers past papers to the public!</title><link>http://blogs.msdn.com/ricom/archive/2008/02/12/computer-measurement-group-offers-past-papers-to-the-public.aspx</link><pubDate>Tue, 12 Feb 2008 20:44:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7648608</guid><dc:creator>ricom</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/ricom/comments/7648608.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=7648608</wfw:commentRss><description>&lt;p&gt;As you know I presented my &lt;a href="http://blogs.msdn.com/ricom/archive/2007/02/07/performance-signatures-cmg-2006-paper.aspx"&gt;performance signatures paper&lt;/a&gt; at the Computer Measurement Group's (CMG) conference a little over a year ago and I am happy to announce that CMG is now offering previous &lt;a href="http://www.cmg.org/proceedings/"&gt;proceedings from 2005 and older to the public&lt;/a&gt;.&amp;#160; I think this is a fabulous move by them because there is some first rate content here that just wasn't seeing nearly the light that it deserved to see.&lt;/p&gt;  &lt;p&gt;I hope to provide more specific recommendations when I have had the chance to look at the site myself in more detail and of course&lt;/p&gt;  &lt;p&gt;If you're looking for a way to grow as a performance professional this could be a fabulous resource for you.&amp;#160; I thoroughly enjoyed the event and the presentations when I went.&lt;/p&gt;  &lt;p&gt;See &lt;a title="http://www.cmg.org/proceedings/" href="http://www.cmg.org/proceedings/"&gt;http://www.cmg.org/proceedings/&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7648608" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/recommendations/default.aspx">recommendations</category></item><item><title>Performance Quiz #13 -- Linq to SQL compiled query cost -- solution</title><link>http://blogs.msdn.com/ricom/archive/2008/01/14/performance-quiz-13-linq-to-sql-compiled-query-cost-solution.aspx</link><pubDate>Mon, 14 Jan 2008 20:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7110071</guid><dc:creator>ricom</dc:creator><slash:comments>18</slash:comments><comments>http://blogs.msdn.com/ricom/comments/7110071.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=7110071</wfw:commentRss><description>&lt;P&gt;Well is there really a "solution" at all in general?&amp;nbsp; This particular case I think I constrained enough that you can claim an answer but does it generalize?&amp;nbsp; Let's look at what I got first, the raw results are pretty easy to understand.&lt;/P&gt;
&lt;P&gt;The experiment I conducted was to run a fixed number of queries (5000 in this case) but to break them up so that the compiled query was reused a decreasing amount.&amp;nbsp; The first run is the "best" 1 batch of 5000 selects all using the compiled query.&amp;nbsp; Then 2 batches of 2500, and so on down to 5000 batches of 1.&amp;nbsp; As a control I also run the uncompiled case at each step expecting of course that it makes no difference.&amp;nbsp; Note the output indicates we selected a total of 25000 rows of data -- that is 5 per select as expected.&amp;nbsp; Here are the raw results:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Testing 1 batches of 5000 selects &lt;BR&gt;5000 selects uncompiled 9200.0ms 25000 records total 543.48 selects/sec &lt;BR&gt;5000 selects compiled 5401.0ms 25000 records total 925.75 selects/sec &lt;/P&gt;
&lt;P&gt;Testing 2 batches of 2500 selects &lt;BR&gt;5000 selects uncompiled 9181.0ms 25000 records total 544.60 selects/sec &lt;BR&gt;5000 selects compiled 5402.0ms 25000 records total 925.58 selects/sec &lt;/P&gt;
&lt;P&gt;Testing 5 batches of 1000 selects &lt;BR&gt;5000 selects uncompiled 9169.0ms 25000 records total 545.32 selects/sec &lt;BR&gt;5000 selects compiled 5432.0ms 25000 records total 920.47 selects/sec &lt;/P&gt;
&lt;P&gt;Testing 100 batches of 50 selects &lt;BR&gt;5000 selects uncompiled 9184.0ms 25000 records total 544.43 selects/sec &lt;BR&gt;5000 selects compiled 5511.0ms 25000 records total 907.28 selects/sec &lt;/P&gt;
&lt;P&gt;Testing 1000 batches of 5 selects &lt;BR&gt;5000 selects uncompiled 9166.0ms 25000 records total 545.49 selects/sec &lt;BR&gt;5000 selects compiled 6526.0ms 25000 records total 766.17 selects/sec &lt;/P&gt;
&lt;P&gt;Testing 2500 batches of 2 selects &lt;BR&gt;5000 selects uncompiled 9165.0ms 25000 records total 545.55 selects/sec &lt;BR&gt;5000 selects compiled 7892.0ms 25000 records total 633.55 selects/sec &lt;/P&gt;
&lt;P&gt;Testing 5000 batches of 1 selects &lt;BR&gt;5000 selects uncompiled 9157.0ms 25000 records total 546.03 selects/sec &lt;BR&gt;5000 selects compiled 10825.0ms 25000 records total 461.89 selects/sec&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And there you have it.&amp;nbsp; Even at 2 uses the compiled query still wins but at 1 use it loses.&amp;nbsp; In fact, the magic number for this particular query is about 1.5 average uses to break even.&amp;nbsp; But why?&amp;nbsp; And how might it change?&lt;/P&gt;
&lt;P&gt;Well, as has been observed in the comments, Linq query compilation isn't like regular expression compilation.&amp;nbsp; In fact compiling the query doesn't do anything that isn't going to have to happen anyway.&amp;nbsp; In fact, actually creating the compiled query with Query.Compile hardly does anything at all, it's all deferred until the query is run just as it would have been had the query not been compiled.&amp;nbsp; So what is the overhead?&amp;nbsp; Why is it slower at all?&amp;nbsp; And what's the point of it?&lt;/P&gt;
&lt;P&gt;Well the main purpose of that compiled query object is to have an object, of the correct type, that also has the correct lifetime.&amp;nbsp; The compiled query can live across DataContexts, in fact it could potentially live for the entire life of your program.&amp;nbsp; And since it has no shared state in it, it's thread-safe and so forth.&amp;nbsp; It exists to:&lt;/P&gt;
&lt;P&gt;1) Give the Linq to SQL system a place to store the results of analyzing the query (i.e. the actual SQL plus the delegate that will be used to extract data from the result set)&lt;/P&gt;
&lt;P&gt;2) Allow the user to specify the "variable parts" of the query.&amp;nbsp; The most common case isn't that the query is exactly the same from run to run, usually it's "nearly" the same... That is it's the same except that perhaps the search string is different in the where clause, or the ID being fetched is different.&amp;nbsp; The shape is the same.&amp;nbsp; Creating a delegate with parameters allows you to specify which things are fixed and which things are variable.&lt;/P&gt;
&lt;P&gt;Now there was some debate about how to make compiled queries durable, automatically caching them was considered, but this was something I was strongly against.&amp;nbsp; Largely because of the object lifetime issues it would cause.&amp;nbsp; First, you would have to do complicated matching of a created query against something that was already in the cache -- something I'd like to avoid.&amp;nbsp; Secondly you have to decide where to store the cache, if you associate it with the DataContext then you get much less query re-use because you only get a benefit if you run the same query twice in the same data context.&amp;nbsp; To get the most benefit you want to be able to re-use the query across DataContexts.&amp;nbsp; But then, do you make the cache global?&amp;nbsp; If you do you have threading issues accessing it, and you have the terrible problem that you don't know when is a good time to discard items from the cache.&amp;nbsp; Ultimately this was my strongest point, at the Linq data level we do not know enough about the query patterns to choose a good caching policy, and, as I've written many times before, when it comes to caching good policy is crucial.&amp;nbsp; In fact, analogously, we had to make changes in the regular expression caching system back in Whidbey precisely because we were seeing cases where our caching assumptions were resulting in catastrophically bad performance (Mid Life Crisis due to retained compiled regular expressions in our cache) --&amp;nbsp; I didn't want to make that mistake again.&lt;/P&gt;
&lt;P&gt;So that's roughly how we end up at our final design.&amp;nbsp; Any Linq to SQL user can choose how much or how little caching is done.&amp;nbsp; They control the lifetime, they can choose an easy mechanism (e.g. stuff it in a static variable forever) or a complicated recycling method depending on their needs.&amp;nbsp; Usually the simple choice is adequate.&amp;nbsp; And they can easily choose which queries to compile and which to just run in the usual manner.&lt;/P&gt;
&lt;P&gt;Let's get back to the overhead of compiled queries.&amp;nbsp; Besides the one-time cost of creating the delegate there is also an little extra delegate indirection on each run of the query plus the more complicated thing we have to do: since the compiled query can span DataContexts we have to make sure that the DataContext we are being given in any particular execution of a compiled query is compatible with the DataContext that was provided when the query was compiled the first time.&lt;/P&gt;
&lt;P&gt;Other than that the code path is basically the same, which means you come out ahead pretty quickly.&amp;nbsp; This test case was, as usual, designed to magnify the typical overheads so we can observe them.&amp;nbsp; The result set is a small number of rows, it is always the same rows, the database is local, and the query itself is a simple one.&amp;nbsp; All the usual costs of doing a query have been minimized.&amp;nbsp; In the wild you would expect the query to be more complicated, the database to be remote, the actual data returned to be larger and not always the same data.&amp;nbsp; This of course both reduces the benefit of compilation in the first place but also, as a consolation prize, reduces the marginal overhead.&lt;/P&gt;
&lt;P&gt;In short, if you expect to reuse the query at all, there is no performance related reason not to compile it.&amp;nbsp; &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7110071" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/databases/default.aspx">databases</category><category domain="http://blogs.msdn.com/ricom/archive/tags/quiz/default.aspx">quiz</category></item><item><title>Performance Quiz #13 -- Linq to SQL compiled queries cost</title><link>http://blogs.msdn.com/ricom/archive/2008/01/11/performance-quiz-13-linq-to-sql-compiled-queries-cost.aspx</link><pubDate>Fri, 11 Jan 2008 23:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7078749</guid><dc:creator>ricom</dc:creator><slash:comments>28</slash:comments><comments>http://blogs.msdn.com/ricom/comments/7078749.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ricom/commentrss.aspx?PostID=7078749</wfw:commentRss><description>&lt;P&gt;I've written a few articles about Linq now and you know I was a big fan of &lt;A href="http://blogs.msdn.com/ricom/archive/2007/06/22/dlinq-linq-to-sql-performance-part-1.aspx" mce_href="http://blogs.msdn.com/ricom/archive/2007/06/22/dlinq-linq-to-sql-performance-part-1.aspx"&gt;compiled queries in Linq&lt;/A&gt; but what do they cost?&amp;nbsp; Or more specifically, how many times to you have to use a compiled query in order for the cost of compilation to pay for itself?&amp;nbsp; With regular expressions for instance it's usually a mistake to compile a regular expression if you only intend to match it against a fairly small amount of text.&lt;/P&gt;
&lt;P&gt;Lets do a specific experiment to get an idea.&amp;nbsp; Using the ubiquitous Northwinds database and getting the same data over and over to control for the the cost of the database accesses (and magnify any Linq overheads) we run this query:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;var q = (from o in nw.Orders &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; select new { &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; OrderID = o.OrderID, &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; CustomerID = o.CustomerID, &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; EmployeeID = o.EmployeeID, &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; ShippedDate = o.ShippedDate &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }).Take(5);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;and compare it against:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;var fq = CompiledQuery.Compile &lt;BR&gt;( &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (Northwinds nw) =&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; (from o in nw.Orders &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; select new &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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OrderID = o.OrderID, &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CustomerID = o.CustomerID, &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EmployeeID = o.EmployeeID, &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ShippedDate = o.ShippedDate &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;&amp;nbsp;&amp;nbsp;&amp;nbsp; }).Take(5) &lt;BR&gt;);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So now the quiz:&amp;nbsp; How many times to I have to use the compiled version of the query in order for it to be cheaper to compile than it would have been to just use the original query directly?&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7078749" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ricom/archive/tags/performance/default.aspx">performance</category><category domain="http://blogs.msdn.com/ricom/archive/tags/databases/default.aspx">databases</category><category domain="http://blogs.msdn.com/ricom/archive/tags/quiz/default.aspx">quiz</category></item></channel></rss>