Basic points that can help to Improve Web Application Performance

1. Disable View State Of A Page If Possible:
Page that does not require any post back events can have the view State off. By default the “ViewState” property is enabled, we can disable it in two ways:
(a) At control level: by set EnableViewState property to false
(b) At page level: using <%@ Page EnableViewState=”false” %>

Advantage: It decreases the memory allocation on server.

2. Use of String Builder For Concatenation:
All operations we do on strings are stored in memory as separate references. When we modify our string, at run time it returns a new string, leaving the previous string as garbage collected. To stop creation of new references we should use string builder whenever concatenation is required.

3. Dispose Resource After Use:
Always dispose object after use. The best way to do that is to use final block to dispose them. Example: When we create object of a DataTable in our code it allocates memory for that object on the managed heap. The object remains on the heap until it’s no longer referenced by any active code, at which point the memory its using is Garbage. So we need to dispose the object to free memory allocation.

Another way is to use “using” when we use IDisposable object we should use it in a using statement.  A “using” statement ensures that object is disposed even in case of exception.  Example : the datatable will be disposed even if error occurs in this using block.

using (DataTable dt = (DataTable)Session["Test"])

4. Use Client Site Validation:
Client site validation can help reduce round trips that are required to process user’s   request. You can also use client side controls to validate user input.
Note: a check at the Server side too to avoid the infamous JavaScript disabled scenarios.

5. Use Ajax UI:
Avoid full page refresh and update only the portion of the page that need to be refreshed.

6. Use Paging in Grid:
It is important to use paging to show small number of data at once. It makes the loading of grid faster.

7. Use of Caching:
It is good practice to use caching results for better performance. We can cache the content of the page or full page, but caching is not suited for all scenario. We should use caching if the data that we need to show change infrequently.

8. Minimize Server Control:
During designing a new page we use <div> tag but unknowingly if we do <div id=”div1” runat=”server”> it increases the response time of the page because it needed to be processed on the server site before it render on the client site. So use HTML elements where they can be used .

9. Avoid Unused Assemblies: 
Don’t add unwanted using in the page.

10. Make JavaScript And CSS External:
External files generally produce faster pages because the JavaScript and CSS files are cached by the browser. With cached external files, the size of the HTML is kept small without increasing the number of HTTP requests thus improving the performance.

11. Set Debug=”false” :
Set debug=”false” in web config by default it is “true” for development point of view it is good but when we deploy it to server it must be false as when we set true it require PDB information that needed to be inserted into file and the size of that file is large which and hence the processing is slow.

12. Use IsPostBack: page has a property IsPostBack which help to determine that the page is rendered first time or not. Generally it is used in Page_load event like,

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
//function that needed to be called only once in the page like
//Drop down bind etc

13. Use DataReader:
We should use DataReader wherever possible. DataReader provide a buffered stream of data. It should be used where we have a large amount of data as the data is not cached in memory.

14. Pre-Compiling of Application:
Often we found while deploying we use two approach either we use code file or other one is pre-compiling our website and then deploy it. Precompile is the better practice as it provides the fast response to the user since code files do not have to be compiled first time when they requested.

15. Declare Variable Carefully:
It’s often notice when writing code we declare variables anywhere even if it is a local variable. Try to declare variable near to its use. Suppose if your code has more than 100 lines (well it is not advised to make that long methods) and you declare the variable in the start of the method and it’s used it in the end than the variable hold memory for that long.

Written By: Vipin Joshi, ASP.Net Developer, Mindfire Solutions

Posted on August 8, 2013, in ASP.Net and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: