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.
- 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.
- Use Page.IsPostBack property to minimize redundant processing. Confirm that only data is loaded on first time page load.
- Use HttpServerUtility.Transfer method.
- Use StringBuilder for large string manipulation. Strings are immutable. The large is string operation you need the more benefit you can get from StringBuilder.
- Avoid unnecessary type conversions. Type casting is costly so do it only when necessary.
- Use ViewState only when necessary. Use of ViewState increase page size which increase traffic load on network.
- Restrict use of Session state. Use of Session and Application state directly have affect on server memory.
- Remove unnecessary using’s.
- Build your application on Release mode. Release mode avoid including debug information which increase execution of application.
- Precompile your Application.
- Use Asp.Net Caching.
- Enable buffering.
- Use transaction properly.
- Limit use of Asp.Net Server controls.
- Use client side validation.
- Don’t rely on Exception.
- Use finally block to dispose unnecessary objects.
- Avoid unnecessary round trip to the server.
- Avoid Use of ViewState encryption unless necessary.
- Disable Debug mode.
- Rewrite call incentive COM components in managed code.
- Avoid blocking and long running tasks.
- Take advantage of HttpResponse.IsClientConnect before performing large operation.
- Optimize extensive loops. for loop is faster than foreach loop. Use for loop where possible.
- Avoid using deep hierarchy of controls.
- Avoid using Page.DataBind.
- Minimize calling DataBinder.Eval.
- Use Repeater when you need to display read only data.
- Consider using ListView instead of GridView.
- Use Response.Write for formatting output.
- Use paging properly for large result sets. ListView or GridView that may contain more than 20 rows should have paging allowed.
- Use SSL only for pages that require it.
- Disable tracing and debugging.
- Consider using HTTP compression.
- Reduce No of HTTP requests.
- Removed unnecessary white space from page.
- Avoid MS Ajax, Consider using light weight java script library like JQuery, ExtJs etc.
- Use index on all foreign keys.
- Minimize use of cursor.
- Minify JS files while deploying.
- Put CSS on top of page.
- Put JS on bottom of page.
- Make css and java script files external.
- Use Content Deliver Network for static content.
- Consider CSS and Image sprite to reduce number of request.
- Do not scale image in HTML.
- Batch SQL Statement to reduce round trip.
- Use SETNOCOUNT ON in stored procedure.
- Use SET TRANSACTION ISOLATION LEVEL READ COMMITTED below SETNOCOUNT ON and before SELECT queries to ensure no locks during reads.
- Consider index on columns used in Where, Order by, Group by and Distinct clause.
- Use Stored Procedure for Data Access.
- Use DataReader class for fast forward only data cursor.
- Rewrite inefficient queries to improve performance.
- Write paged queries to ensure that you retrieve only required data from database.
- Consider using connection pooling.
nice
ReplyDelete