High Performance ASP.NET – Speeding Up ASP.NET Pages

I have been writing a series of blog posts, which I have coined High Performance ASP.NET Websites Made Easy!  There is no rhyme or reason to the order of these posts and certainly can be read in any order:



The premise behind the ideas presented in these posts are that they must be 1) Dang Near Effortless, 2) Require Very Little Expertise, 3) Leverage Built-In .NET Features or Tools, 4) Easy to Maintain, and 5) Offer Decent Bang For Your Buck


 


Speeding Up ASP.NET Pages


Speeding up ASP.NET Pages can be done in several ways.  Below are 3 categories that come to mind and are not complete by any means:



  • Reduce Page Processing:  Eliminating PostBacks, Caching Output, Avoiding Chatty Interfaces, Avoiding Web Controls

  • Reduce Page Sizes: Limit sizes of ViewState, HTML, JavaScript, and Images

  • Improve (Faster) Page Rendering: CSS instead of Tables

 


Reduce Page Processing


We talked about reducing page processing by short-circuiting the HTTP Pipeline by using ASP.NET Caching.


By caching entire pages or usercontrols, you can eliminate quite a bit of processing done on the page and its controls.  In fact, if you do entire page caching, HTTP Headers are sent in the HTTP Response that tells the proxy server and browser it is okay to cache the page, which may keep your web server from being hit by future requests of the same page.


An additional tip to reduce page processing is to avoid web controls all together.  Don’t use ASP.NET web controls for static information.  Stick to the generic HTML controls that we all knew and love before ASP.NET was ever invented.


An old solution packaged with a new name, AJAX, eliminates entire page postbacks, which also reduces page processing.  I recommend being careful with this as too much AJAX can be a maintenance headache and is certainly not effortless.


 


Reducing Page Sizes


A very simple and effective way of increasing the performance of your ASP.NET application is to reduce the page size.


ASP.NET aside for a moment, the less HTML being streamed back to the browser the faster the page.  You want to reduce the amount of HTML, the size of images, the size of javascript files, etc.


A note about image sizes.  At the Tampa Code Camp, someone thought that changing the width and height attributes of an image caused ASP.NET to reduce the size of the image being streamed to the browser.  This isn’t the case.  The height and width settings on an image are for display purposes only.  If you have a 640 x 480 image, the entire image will be streamed to the browser even if you are only displaying 100 x 100.  Better to open up your favorite image editor and reduce the image to 100 x 100 for faster performance if it makes sense.


Although I wouldn’t recommend it unless absolutely necessary, you can download free tools that will compress / eliminate the white space in HTML and javascript files.  This could be a maintenance nightmare.  You may want to checkout IIS plugins that will do it for you without physically changing your source files.


Specific to ASP.NET, you want to be careful about the size of your ViewState.  Turn-off ViewState on controls if you can, especially on DataGrids, Repeaters, DataLists, and GridViews that tend to be huge if not kept in check.  The most effortless idea here is that ASP.NET pages that don’t postback to themselves don’t require a ViewState.  Turn off ViewState altogether on those pages.


 


Improve (Faster) Page Rendering


Using CSS instead of tables will cause the browser to render your pages faster.  Boy I love tables, but I have been slowly trying to get better and better at using CSS to layout my pages.


I am not an expert on this subject, so I point you to an interesting tutorial on CSS and the benefits of using it over tables:



 


Conclusion


To speed up you ASP.NET Pages, you want to look at a minimum of 3 things:  1) Reducing Page Processing, 2) Reducing Page Sizes, and 3) Faster Page Rendering.  Much of the page processing time can be reduced using tricks we mentioned before, such as caching, eliminating chatty interfaces, and preferring HTML tags over ASP.NET web controls.  Page sizes can be reduced by reducing the file sizes of HTML, images, javascript, and the ASP.NET ViewState.  For faster page rendering, use CSS to eliminate tables to improve performance.


 


Resources


Various articles of interest:



 


DrinkingGyokuro Green Tea


Listening To:  Sandstorm by Darude


 

This entry was posted in ASP.NET. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

3 Responses to High Performance ASP.NET – Speeding Up ASP.NET Pages

  1. Josh says:

    Yeah, as I was typing it, I kinda realized I was answering my own question.

    I totally agree with your clarification. I think it was the “avoid web controls all together” phrase, in bold, that triggered a need to react.

  2. dhayden says:

    I think you answered your own question. WebControls get rendered based on the user agent, etc., which is different than plain-old HTML controls that get bundled in a LiteralControl in the control hierarchy. Therefore, they are slower.

    I think my paragraph is perhaps poorly written, because I wasn’t suggesting that you totally avoid webcontrols. I was just suggesting that you can speed up your page by using standard HTML controls instead of webcontrols. A good place to use normal HTML controls is where you are just displaying static text / images. I am not suggesting you avoid them all together.

    As far as how much faster it will make the page process, could be none or could be noticeable if you have a significant number of controls on the page.

    These are just tips to consider and I wanted to be complete as possible.

    Thanks for the comment.

  3. Josh says:

    Why do you say avoid WebControls? Is that recommendation based on actual metrics, or just theory?
    The way I understand it, ALL markup on an ASPX page gets turned into controls (static HTML tags become instances of LiteralControl) when the request gets processed. So why would having your own WebControls on the page be worse?
    Also, WebControls provide the benefit of an abstraction layer. When using WebControls, the ASP.NET engine determines the correct HTML to render based on the user agent.
    We COULD all code in assembly…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>