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.


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