Quick & Simple optimization tips

Some quick'n'dirty optimization tips:

1.  Be aware that your app will typically spend 95% of it's time in 5% of the code.  Invest time on optimizing only where it will really matter.

2. Also be aware that the actual 5% of the code which is taking all the time probably isn't where you might guess.  Thats what debuggers are for...

3. XML is great for almost everything except performance. If you are using XML as a data structure in your internal loops, you can sometimes gain a x10 or more perf improvement by preloading the data into specialized, indexed data structures such as hashtables or datasets.

4. RegExes can be serious perf drags. Use with care, especially within loops.

These rules alone resulted in an overall 1000% perf improvement in a framework I am currently developing, and it wasn't really that slow to begin with!

Some open questions from my to-do list:

A. When dealing with large numbers of small objects (such as 50K instances of a 50 byte class) what is the impact of using the flyweight design pattern ?

B. Boxing/Unboxing - worth the time/effort of tracking down & eliminating?



Comments (1)
  1. Yura2000 says:


    About paragraph num.4 – RegEx –

    I disagree.

    Really, compiled RegEx leaves himself in memory, even object called him was disposed.

    But this is no situation with RegEx that was not compiled.

    Next – Regex by his idea must eliminate loops.

    Once I’ve checked it with Replace method of the System.String.

    Right builded RegEx pattern(but really right!!!) save up to 90% performance.

    What about it? :-))

Comments are closed.

Skip to main content