Wednesday, November 16, 2011

How can I improve performance and speed of my asp.net web application?

This is a most frequently asked question in asp.net communities. I will list out some points that are important to speed up asp.net web application.
  1. Always use Page.IsValid property. Page.IsValid confirms that all validation controls in page returns valid. Execute server side code only when page is valdated.
  2. Use Page.IsPostBack property to minimize redundant processing. Confirm that only data is loaded on first time page load.
  3. Use HttpServerUtility.Transfer method.
  4. Use StringBuilder for large string manipulation. Strings are immutable. The large is string operation you need the more benefit you can get from StringBuilder.
  5. Avoid unnecessary type conversions. Type casting is costly so do it only when necessary.
  6. Use ViewState only when necessary. Use of ViewState increase page size which increase traffic load on network.
  7. Restrict use of Session state. Use of Session and Application state directly have affect on server memory. 
  8. Remove unnecessary using’s.
  9. Build your application on Release mode. Release mode avoid including debug information which increase execution of application.
  10. Precompile your Application.
  11. Use Asp.Net Caching.
  12. Enable buffering. 
  13. Use transaction properly. 
  14. Limit use of Asp.Net Server controls.
  15. Use client side validation.
  16. Don’t rely on Exception.
  17. Use finally block to dispose unnecessary objects.
  18. Avoid unnecessary round trip to the server.
  19. Avoid Use of ViewState encryption unless necessary.
  20. Disable Debug mode.
  21. Rewrite call incentive COM components in managed code.
  22. Avoid blocking and long running tasks.
  23. Take advantage of HttpResponse.IsClientConnect before performing large operation.
  24. Optimize extensive loops. for loop is faster than foreach loop. Use for loop where possible.
  25. Avoid using deep hierarchy of controls.
  26. Avoid using Page.DataBind.
  27. Minimize calling DataBinder.Eval.
  28. Use Repeater when you need to display read only data.
  29. Consider using ListView instead of GridView.
  30. Use Response.Write for formatting output.
  31. Use paging properly for large result sets. ListView or GridView that may contain more than 20 rows should have paging allowed.
  32. Use SSL only for pages that require it.
  33. Disable tracing and debugging.
  34. Consider using HTTP compression.
  35. Reduce No of HTTP requests.
  36. Removed unnecessary white space from page.
  37. Avoid MS Ajax, Consider using light weight java script library like JQuery, ExtJs etc.
  38. Use index on all foreign keys.
  39. Minimize use of cursor.
  40. Minify JS files while deploying.
  41. Put CSS on top of page.
  42. Put JS on bottom of page.
  43. Make css and java script files external.
  44. Use Content Deliver Network for static content.
  45. Consider CSS and Image sprite to reduce number of request. 
  46. Do not scale image in HTML.
  47. Batch SQL Statement to reduce round trip.
  48. Use SETNOCOUNT ON in stored procedure.
  49. Use SET TRANSACTION ISOLATION LEVEL READ COMMITTED below SETNOCOUNT ON and before SELECT queries to ensure no locks during reads.
  50. Consider index on columns used in Where, Order by, Group by and Distinct clause.
  51. Use Stored Procedure for Data Access.
  52. Use DataReader class for fast forward only data cursor.
  53. Rewrite inefficient queries to improve performance.
  54. Write paged queries to ensure that you retrieve only required data from database.
  55. Consider using connection pooling.

Thanks

1 comment: