65.9K
CodeProject is changing. Read more.
Home

Improve ASP.NET Web Application Performance

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.43/5 (7 votes)

Apr 8, 2010

CPOL

3 min read

viewsIcon

28462

Tips on how to improve ASP.NET web application performance

1) Turn off Tracing unless until required 2) Turn off Session State, if not required 3) Disable View State of a Page if possible 4) Set debug=false in web.config 5) Avoid Response.Redirect 6) Unnecessary round trips 7) Avoid throwing exceptions 8) Use Finally method to kill resources 9) Use Client Side Scripts for validations 10) Avoid unnecessary round trips to the server 11) Use Page.ISPostBack 12) Include Return statements with in the function/method 13) Use Foreach loop instead of For loop for String Iteration 14) Avoid unnecessary indirection 15) Use "ArrayLists" in place of arrays 16) Always check Page.IsValid when using Validator Controls 17) Use Paging 18) Store your content by using caching 19) Use low cost authentication 20) Minimize the number of web server controls 21) Avoid using unmanaged code 22) Avoid making frequent calls across processes 23) Cleaning Up Style Sheets and Script Files 24) Design with ValueTypes 25) Minimize assemblies 26) Encode using ASCII when you don't need UTF 27) Avoid Recursive Functions / Nested Loops 28) Minimize the Use of Format () 29) Place StyleSheets into the Header 30) Put Scripts to the end of Document 31) Make JavaScript and CSS External 32) Use StringBuilder when alter a string.In C# a string is immutable and cannot be altered, its actually creating a new string, which in turn uses more memory than necessary, creates more work for the garbage collector and makes the code execution run slower. 33) For casting an object to another object, use as operator 34) Choose readonly over const. Becuase const evaluated at compile-time which means if it's changed at a later date, you have to not only recompile that application, but all applications that reference that application. In constrast, readonly is evaluated at run-time providing you a lot more flexibility. For Database Operations 1) Return Multiple Resultsets 2) Connection Pooling and Object Pooling 3) Use SqlDataReader Instead of Dataset wherever it is possible 4) Keep Your Datasets Lean 5) Avoid Inefficient queries 6) Avoid joining as much as possible 7) Unnecessary round trips 8) Too many open connections 9) Avoid Transaction misuse 10) Avoid Normalized tables 11) Reduce Serialization 12) Do Not Use CommandBuilder at Run Time 13) Use Stored Procedures whenever possible 14) Avoid Auto-Generated commands 15) Use Sequential Access as often as possible 16) Use commandParameter for passing parameter in stored procedure/query 17) In case of passing commandParameter specify datatype length if possible 18) Implement paging at stored procedure level, retrieve only chunk of data that you need to display after paging. ASP.NET applications developed using VB: 1) Enable Option Strict and Option Explicit for your pages 2) Use early binding in Visual Basic or JScript code 3) Put Concatenations in One Expression 4) Avoiding Use of Class Destructors. Class destructors (implemented as the Finalize() method in VB.NET) cause extra overhead for the garbage collector, because it must track which objects have been finalized before their memory can be reclaimed Some other points to remember 1) Do not overload you App_Code folder with DAL/BLL codes.Use separate layer for them 2)Minimizing Method Calls by investigating common functions 3) Avoid over use of collection 4)The .NET garbage collection scheme can intentionally delay reclamation of objects until memory is available, so keep in mind how you are playing with objects