Monday, August 14, 2006

Performance Rules from Microsoft FxCop 1.35

Performance Rules from Microsoft FxCop 1.35

Following are some of the rules from fxcop to identify performance related issues in your modules.


  1. Avoid costly calls where possible
  2. Avoid calls that require unboxing
  3. Avoid excessive locals
  4. Avoid uncalled private code
  5. Avoid uninstantiated internal classes
  6. Avoid unnecessary string creation
  7. Avoid unsealed attributes
  8. Avoid unused parameters
  9. Dispose methods should call SuppressFinalize
  10. Do not call properties that clone values in loops
  11. Do not cast unnecessarily
  12. Do not concatenate strings inside loops
  13. Do not ignore method results
  14. Do not initialize unnecessarily
  15. Initialize reference type static fields inline
  16. Override equals and operator equals on value types
  17. Prefer jagged arrays over multidimensional
  18. Properties should not return arrays
  19. Remove empty finalizers
  20. Remove unused locals
  21. Test for empty strings using string length
  22. Use literals where appropriate

MS FxCop can be used to identify your application performance related problems with the above rules from its rule engine.

The description and sample code of each rule is available in FxCop documentation.

Friday, August 04, 2006

Performance Optimization - Explicitly Dispose or Close all the resources

Explicitly Dispose or Close all the resources: To guarantee resources are cleaned up when an exception occurs, use a try/finally block. Close the resources in the finally clause. Using a try/finally block ensures that resources are disposed even if an exception occurs. Open your connection just before needing it, and close it as soon as you're done with it. Your motto should always be "get in, get/save data, get out." If you use different objects, make sure you call the Dispose method of the object or the Close method if one is provided. Failing to call Close or Dispose prolongs the life of the object in memory long after the client stops using it. This defers the cleanup and can contribute to memory pressure. Database connection and files are examples of shared resources that should be explicitly closed.

Ref : http://www.codeproject.com/useritems/ASPNET_Best_Practices.asp
    follow me on Twitter