Click here to Skip to main content
Click here to Skip to main content

Tagged as

Improve ASP.NET Web Application Performance

, 2 Jul 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

keyur soni
Software Developer (Senior) Wipro
India India,Ajax,Webparts,Web service,Window application,Window service,Sql Server

Comments and Discussions

GeneralNice PinmemberMember 28244291-Feb-12 22:47 
Generalxcvcxv PinmemberMember 28244291-Feb-12 22:47 
GeneralReason for my vote of 5 Good tips PinmemberShahriar Iqbal Chowdhury4-Jul-10 9:09 
GeneralReason for my vote of 5 Excellent PinmemberShahriar Iqbal Chowdhury2-Jul-10 10:08 
GeneralGood points but.... PinmemberHemant-Kularia28-Apr-10 22:17 
Hi Keyur you've mentioned good points but don't you think many points should be scenario based for Ex:
9) Use Client Side Scripts for validations- What if security is the concern?

20)Minimize the number of web server controls
- its not so often we use more server controls than required.
21) Avoid using unmanaged code- Again we use unmanaged only when it is required. Same thing goes with Recursive functions (point No 27) it is normally used when you need it for ex. listing all files and subdirectories in an directory.
30) Put scripts to the end of the document
- I didn't get this point. how come Putting scripts at the end of the document will improve the performance? Is it javascript? if it's javascript it can avoid errors while invoking functions at/ before body load.
2) Use early binding in Visual Basic or JScript code
- what if there are lots of statements after declaring the object and after that we are assigning values to the object, and some error occured during this? I mean in that case dont you think late binding is good option?

otherwise you mentioned good points
Hemant Kularia

GeneralRe: Good points but.... PinmemberNiklas Lindquist2-Jul-10 0:04 
GeneralGood One to implement PinmemberChetan Patel13-Apr-10 9:25 
GeneralRe: Good One to implement Pinmemberkeyur soni14-Apr-10 3:21 
GeneralGreat tip PinmemberGaurav Dudeja India8-Apr-10 21:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 2 Jul 2010
Article Copyright 2010 by keyur soni
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid