Geeks With Blogs
Ankit Agrawal

For more formatted view .. Goto http://ankitagrawal57.blogspot.com/

For any web application, performance is basic necessity. Earlier internet speed used to be limited thus users got inclined to pages which load within 3-4 secs. But now the internet speed is no more a constraint but still time does remain a constraint. Imagine yourself visiting a website which takes a lot of time (30 – 60 secs) just to load the page. You would not like to go to that site again.

To mitigate this issue, developers and designers work a lot towards improvement of performance. I too worked on this and found out some key things that might be useful to others. I am not reinventing the tips, I am just trying to collate all the tips that I found useful while my development and performance optimization. Starting off with the UI, I will list down all key features that can be used to improve performance. Hope the journey with this document goes well. Please provide any comment or feedback if you feel otherwise. I would be more than happy to incorporate it.

1. Web Controls

a. Page: 

i. Avoid Tables. Use Div,span in place of them.

ii. Place CssClass instead of assigning style on tag. This will reduce the text in html file (as only one class name is replaced by multiple styles)

iii. Join Css, Js files.

iv. Use Css in place of Javascript wherever possible. For example, for hover, use Css class instead of writing JS.

v. Use multiple servers for parallel downloads of resources.

b. Custom Controls: If you are making a custom control or overriding the render mechanism of a control, keep in mind following things:

i. Using Div,Span tags adds to performance in comparision to Table. For example, Asp.net Treeview control uses Table/Tr/Td to render the treeview. This makes this control heavy. Use can make your own custom control which renders in Div/Span and will give better performance when playing with large data (2000 treenodes).

ii. IE (6-8) works in a weird way with long string. If your control is big with many html tags or a series of tags (like 2000 treenodes for a custom tree view), IE will take time to render that control. Placing Environment.NewLine in the tags somehow increases the performance. 

2. Javascript

a. Javascript accelerator on IE: One common issue that developers face – Page opens up fast in Firefox and chrome while it takes a hell lot of time on IE (6-8). In my case, IE used to hang and then restart itself after 30-40 seconds. This issue due to the rendering engine that browsers use. IE (6-8) uses Trident (3,4 version). This didn’t have hardware acceleration for javascript and jquery. Other engines (Chrome, Firefox) uses hardware accelerator for javascript. This was problem when page have a lot of javascript which will iterate through the whole page and search for an object. So any loop in javascript (with 1000 or more iteration will have performance impact). Check it out here.

b. Modifying DOM object: Remember that modifying a DOM object in javascript will impact the performance of the web page.

c. Compress Javascript: The javascript you deploy on test or production server should be well compressed. This will again improve the performance as the compressed file be of less size and smaller variable names. Freely available tools are 

i. http://dean.edwards.name/packer/

ii. http://javascriptcompressor.com/

d. Jquery Selector: Use Jquery selector wisely. What it does internally is, iterate through all the DOM objects in the page and select the objects that meets the criteria. Prefer using :First, :Last, etc. Or put a wrapper element (like div) and run the selector on that. This will reduce the number of objects to be searched. 

i. Try avoiding selector on class name. Instead try to select the element by id. Class selector will iterate through the whole DOM object while element selector will break when it finds the element.

3. Service: Use REST based WCF service for fetching or updating data. REST service is faster and can be cached. So application will gain performance.

4. Database (SQL Server 2008)

a. Use following where ever applicable:

i. Use “Exists” more. It serves with better performance.

ii. Use CTE (Common Table Expressions) instead of temporary table 

b. Following 2 Procedures have different performance. If you see the plan for execution in both the case, it will be apparent that the second one will have more “Estimated Number of Rows”. While first one will have only 1.

(Note: ID is Primary Index field in Table1.)

i. Create ProcName 

  @Id Int

AS

BEGIN

  Select * from Table1 Where Id = @Id

END

ii. Create ProcName 

  @Id Int

AS

BEGIN

Declare @myId int

Set @myId = @Id

  Select * from Table1 Where Id = @myId

END

This is because the first one will be considered as constant and thus the execution plan will estimate that the rows to scan is 1 while in second case, the execution plan would be different

c. Service Broker: This new technology, a part of the Database Engine, provides a message-based communication platform that enables independent application components to perform as a functioning whole. Service Broker includes infrastructure for asynchronous programming that can be used for applications within a single database or a single instance as well as for distributed applications.


Posted on Wednesday, September 21, 2011 3:22 AM | Back to top


Comments on this post: Performance Optimization tips for ASP.NET application

# re: Performance Optimization tips for ASP.NET application
Requesting Gravatar...
Hey Ankit,
Great information in the post but the formatting of your bullet points made it difficult to read.
Left by Mary on Sep 21, 2011 5:17 AM

# re: Performance Optimization tips for ASP.NET application
Requesting Gravatar...
for formatted view, you can visit my google blog :

http://ankitagrawal57.blogspot.com/

Here, i tried formatting but the editor doesnt support it
Left by Ankit on Sep 21, 2011 6:07 AM

# re: Performance Optimization tips for ASP.NET application
Requesting Gravatar...
nice article.
Could you please give the example of execution plane in sql server2008
Left by Jitendra on May 17, 2013 4:52 PM

# re: Performance Optimization tips for ASP.NET application
Requesting Gravatar...
super dear i like it
Left by super on Jun 18, 2015 1:03 PM

Your comment:
 (will show your gravatar)


Copyright © AnkitAgrawal | Powered by: GeeksWithBlogs.net