Something NEW?.....Naaa...Not much.

↑ Grab this Headline Animator

Wednesday 26 December 2007

Managed Code Performance, A Checklist - Part 1/3

Design Considerations:
- Design for efficient resource management.
- Reduce boundary crossings
- Prefer single large assemblies rather than multiple smaller assemblies.
- Factor code by logical layers
- Treat threads as a shared resource.
- Design for efficient exception management.

Class Design considerations:
- Do not make classes thread safe by default.
- Consider using the sealed keyword.
- Consider the tradeoffs of using virtual members
- Consider using overloaded methods.
- Consider overriding the Equals method for value types.
- Know the cost of accessing a property.
- Consider private versus public member variables.
- Limit the use of volatile fields.

Garbage Collection Guidelines
- Identify and analyze your application's allocation profile.
- Avoid calling GC.Collect
- Consider weak references with cached data.
- Prevent the promotion of short-lived objects.
- Set unneeded member variables to Null before making long-running calls.
- Minimize hidden allocations.
- Avoid or minimize complex object graphs.
- Avoid preallocating and chunking memory.

Finalize and Dispose
- Call Close or Dispose on objects that support it.
- Use the using statement in C#.NET and Try/Finally blocks in VB.NET to ensure Dispose is called
- Do not implement Finalize unless required
- Implement Finalize only if you hold unmanaged resources across client calls.
- Move the finalization burden to the leaves of object graphs.
- If you implement Finalize, implement IDisposable.
- If you implement Finalize and Dispose, use the Dispose pattern.
- Suppress finalization in your Dispose method.
- Allow Dispose to be called multiple times.
- Call Dispose on base classes and IDisposable members.
- Keep finalizer code simple to prevent blocking.
- Provide thread-safe cleanup code only if your type is thread-safe.

Pinning
- If you need to pin buffers, allocate them at startup.

No comments: