Really it's about your choice in algorithms. Usually there is no "silver bullet" for optimization.
For example, using a StringBuilder
instead of concatenation can make your code significantly faster, but there is a tradeoff. If you aren't concatenating huge sets of strings, the memory and time it takes to initialize StringBuilder
is worse than just using regular concatenation. There are a lot of examples of this throughout the framework, such as dictionary caching as you mentioned in your question.
The only general optimization you can really learn and apply to your coding throughout your day is the performance hit from boxing/unboxing (heap vs. stack). To do this you need to learn what it's about and how to avoid, or reduce the need to do it.
Microsoft's MSDN documentation has 2 articles on performance that give a lot of good general purpose techniques to use (they're really just different versions of the same article).
- http://msdn.microsoft.com/en-us/library/ms173196.aspx
- http://msdn.microsoft.com/en-us/library/ms173196(VS.80).aspx