Udostępnij za pośrednictwem


Improve ASP.NET Performance By Disabling ViewState And Setting Session As ReadOnly

During recent engagement we tried to improve performance of some web page. Original response time was 0.74 seconds. Our objective was to get 0.4 seconds.

The page was simple Html Frameset that was loading two dynamic ASPX pages. Using technique described in Performance Testing For The Masses we identified that it takes 0.4  seconds for one page and 0.2 seconds for another to run on the server (we used time-taken property of the IIS log).

Reviewing the code revealed that there is usage of server controls and both pages read from the Session object.

The assumption was that since no user input is done we can disable ViewState saving on CPU to build the ViewState.

The other assumption was that since the Session is accessed for read only then we can set it as read only saving on locking and preventing race conditions.

This is how each page's header looked after the change:

<%@ Page EnableViewState=”false” EnableSessionState=”ReadOnly” ...%>

Simple change for ASP.NET mark up, no rebuild required.

After running load test for this new version of ASPX page response time was 0.35 seconds.

Another metric was ASP.NET\ Request Execution Time performance counter that dropped from 0.7 seconds to 0.3 seconds.

Sweet.

Source of performance wisdom is here Improving .NET Application Performance and Scalability

Enjoy

Comments

  • Anonymous
    August 16, 2007
    I think disabling viewstate is the main reason.Also it is possible to disable:validateRequest="false" enableEventValidation="false"and set compilation debug to false
  • Anonymous
    August 16, 2007
    The comment has been removed
  • Anonymous
    August 17, 2007
    agree regarding security points, howeversetting compilation debug "false" proved to be efficient especially in .net 2.0and it is "true" by default
  • Anonymous
    August 17, 2007
    w/r to debug "The default is False."http://msdn2.microsoft.com/en-us/library/s10awwz0.aspx
  • Anonymous
    January 01, 2008
    During recent few engagements with my customers I've noticed&#160; VIewState is extensively [unintentionally]
  • Anonymous
    January 01, 2008
    During recent few engagements with my customers I&#39;ve noticed&#160; VIewState is extensively [unintentionally
  • Anonymous
    January 21, 2008
    Care about performance? Do you write your code with performance in mind? Want little help to spot performance