Wednesday 23 May 2007

ViewState improvements in ASP.Net 2

I’ve recently been upgrading a project from ASP.Net 1.1 to ASP.Net 2. I’d seen documented that ViewState sizes had been significantly reduced, quoted as up to 50% smaller in some cases. A new serialization format, incorporated in a new formatter class (ObjectStateFormatter) is behind the improvements. See http://www.nikhilk.net/ViewStateImprovements.aspx for further info on how it all works.

Anyhow, I thought it would be interesting to see how much of an improvement I would get on some 'heavy' DataGrid driven data entry intranet pages. Here’s the stats in bytes:

ViewState Size ASP.Net 1.1 (ASP.Net 2)

Page 1: 9892 (7456 75%)
Page 2: 44492 (25696 58%)
Page 3: 39900 (24800 62%)
Page 4: 46300 (23500 51%)

So my worst case was ‘only’ a 75% reduction, but on some pages my ViewState was 51% of the original. Not bad. My advice of course is still to turn off ViewState when not needed ;-)