Code Performance

Creating an instance of a generic paremeter is slooooo

I recently needed to change how an array lookup worked to make it more efficient, and decided to use the List<T>.BinarySearch to do the lookup. The class that contained this lookup had a generic parameter, and was constrained like so: public class SortedNameList<T> where T : class, INameValueItem, new() {...} where the T of List<T> was the same as the class generic parameter. In order to do the BinarySearch, List<T> required an input of type T to search against. Since I only ......

Easily write Reflection.Emit code

I was looking at Refletor addins the other day and ran across one that would be an amazing time saver. Its an addin that generates the Reflection.Emit code! Anyone who has ever spent any time with the Reflection.Emit namespace should immediately realize how wonderful this tool has the potential to be (as long as the generated code is of good quality of course). Also, the way integrates with Reflector is pretty slick. It adds a "Reflection.Emit" choice in the list of languages you want Reflection ......

The Instrumentation Model

I've spent a lot of time lately thinking about instrumentation and how to integrate it into software projects. As a performance engineer I tend to think about instrumentation from the point of view of someone who wants to record the details of what a system is doing, and then dig through the data and use it to figure out what is wrong. But I’ve been talking to people the past few months about instrumentation, I’ve come to realize that instrumentation means different things to different people. Some ......

Code Analysis Tools

I've started working on a collection of code analysis tools, that are open source and available for anyone to use. I've got a descriptive article located at CodeProject.com (http://www.codeproject.com... which includes the source code and binaries. The three main tools that I have so far are the following: A “Not Used Finder”: searches through a list of assemblies and looks for any type, method or field that isnt ever used. Points out code that you should ......

Generic IComparer is a good thing. And null comparisons

There is something I've been wanting to post about for a while, but just didn’t have enough info to make it worth my, or anyone who reads this, while. We all know that .Net 2.0 came out with something wonderful called Generics. I've been profiling a lot of my 1.1 code, comparing it to my 2.0 code that utilizes Generics, and the one change that has given me the greatest, most dramatic performance benefits is to switch from IComparer to IComparer. I use IComparer a LOT. But there is a problem ......

String concatenation the fast way...maybe not what you think

One thing you read in most articles or books that talk about code optimization in .Net is string concatenation. Many books will say always use a StringBuilder to build your strings. Some even go so far as to say use the String.Conct() method for 2-4 strings. But you should never use the + style concatenation. Well I say BULL! The C# compiler folks at Microsoft did a great thing with 1.1 (I don't think its there in 1.0). if you write some code like:private string StringConcatTest(string stuff) { string ......