Shredding, coding, arguing etc.

Viewstate Keys - Does size matter?

16 November 2008

This is just a trivial performance issue that I was curious about.

ASP .NET is known for bloated HTML page sizes. There are a number of reasons for this, all of which can be solved:

  • Lengthy ids generated for dynamic elements (e.g. MyFunkyUserControl_8_MySwankyRepeater_ASmellyTextbox)
  • Lengthy ids repeated in the name attribute
  • Long javascript function names, (e.g. WebForm_GetElementById)
  • Viewstate

If you are storing a lot of information in viewstate, you may be wondering if the size of the key itself contributes to the size of ViewState.

ViewState["MyVeryLongKeyName"] = myValue;
ViewState["MVLN"] = myValue;

Does the shortened key name decrease the size of the HTML being sent across the tubes (at the expense of code readability)? Whilst this may seem trivial, it can make a difference if you are appending unique identifiers, dates etc. to the end of the key.

Answer

The answer, is yes - it does. A key of 20 characters will weigh more than 20 times a key of 1 character (I guess the weight increases even further because of the hashing algorithm).

Should I bother?

If you are creating very large forms, with lots of data stored in ViewState, then you can probably look into reducing the size of your ViewState keys - but only after you have reduced the size of control ids, limited the amount of data being stored in ViewState and turned on GZipping.

Comments

 
   
Stupidity filter

Unfortunately, the internet is rife with automaton zombies that fill up blog threads with rubbish. There are also computer scripts that do this too. Please answer the following question.

Waht is the nmae of the plnaet clsoset to the cneter of the sloar ssyetm?    
  •  
  • del.icio.us  del.icio.us
  • reddit  reddit
  • StumbleUpon  StumbleUpon