studio NETSOULS

Applying Web To Your Business

I’ll show you how you can quickly enable ViewState compression and show you the effects it has on overall ViewState size and server performance.

How do I enable Viewstate compression?

Enabling ViewState compression with the RadCompression module really couldn’t be easier. It requires no changes to your code, no changes to your markup, and not even a change to your web.config (assuming you’ve already added the required HttpModule references). The only thing you need to do is add a new Browser file to your web project (or modify your Browser file if you’re already using one). To add a new Browser file, follow these simple steps:

  • Right-click on your web project, select "Add…" > "Add ASP.NET Folder…" > "App_Browsers"
  • Right-click in your new App_Browsers folder, select "Add…” > "Add New Item…" > "Browser File"
  • The new browser file will have some default values, feel free to delete everything and then add this code:
   1: <browsers>
   2:  <browser refID="Default">
   3:  <controlAdapters>
   4:  <adapter controlType="System.Web.UI.Page" adapterType="Telerik.Web.UI.RadHiddenFieldPageStateCompression" />
   5:  <!--Uncomment the following line to use SessionStateCompression and remove ViewState from the page-->
   6:  <!--<adapter controlType="System.Web.UI.Page" adapterType="Telerik.Web.UI.RadSessionPageStateCompression" />-->
   7:  </controlAdapters>
   8:  </browser>
   9: </browsers>

And that’s it!. Run your project at this point and you’ll discover that the RadCompression module is now automatically compressing your ViewState.

How much does the compression help?

ViewState, as you probably know, is just a serialized string of data. By default, it’s not compressed, it’s not encrypted, and it’s often a bloated piece of string data that gets passed back and forth with every request to the server.

Compressing this data is an easy way to reduce your page size and reduce the number of bytes you must send and receive from the server.

To demonstrate RadCompression’s effectiveness, I created a simple page with a RadGrid that loads data from the AdventureWorks Employees table. I bound my grid declaratively to an EntityDataSource and I slowly started increasing my Grid’s page size- from 10 records to 240 per page. As the page size grew, obviously the ViewState grew.

RadCompression Efficiency

RadCompression Efficiency

The blue bars represent the ViewState size (in KB) with RadCompression. The green bars represent the difference in the original ViewState size (i.e. total size with no compression). And the red numbers indicate the compression “efficiency” at each step (for instance, “53%” means the compressed ViewState was 53% smaller than the original).

  • As the original ViewState grew, the compression became even more “efficient” (ranging from 47% to 75% compression ratios)
  • In the first two tests, there was no difference between the original and the “compressed” output – more on this in a moment
  • On average, RadCompression reduced ViewState size by 61%! (omitting the “0” tests)

So why are the first two tests “0%”? RadCompression actually has a “threshold” that must be passed before compression will kick-in. For smaller ViewState sizes, it doesn’t make sense to apply compression- the overhead of the processing and compression header/footer offset the small gains in overall state size. Currently, this threshold is 8KB. If your original ViewState is smaller than 8KB, RadCompression will automatically skip over it. Bigger than that, and RadCompression will automatically work.

What is the effect on server performance?

Many people will often say, “Sure you can compress ViewState, but doesn’t that add significant processing overhead on the web server?” It is true that adding compression represents extra CPU cycles and it does have an effect on server performance. With RadCompression, though, that impact is relatively small. Internally, RadCompression uses Deflate compression to compress and decompress state, which is much faster than Gzip compression. And thanks to the optimizations of the compression APIs in .NET, the overall effect on server processing time is low.

This may be one of the easiest ways to help reduce your page size, and in turn, help improve your page performance. By simply registering the RadCompression HttpModule and adding a .browser file to your project, you can see reductions of over 70% in your ViewState size with little impact on your server performance. Clearly, as developers we should all be taking active steps to reduce our ViewState size, but if you’ve already done everything you can (or at least everything you have time for) and you want to squeeze a few more KB out of your page, RadCompression is ready and waiting for you in your Telerik toolbox.

  • Currently 0 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

SQL Scripting

  • Keep all the scripts for all the tables, stored procedures, testing queries, enabling and disabling indexes and others in the Visual Studio Database Application properly. We all need to maintain the folder structure.
  • Nomenclature for naming the stored procedures
    • To retrieve records GetTableNameByIdSP - This is for returning only a single record, for returning more records depending upon the business logic write the simple logic name instead of ById.
    • To add records AddNewTableNameSP
    • To edit records UpdateTableNameSP
    • To delete records DeleteTableNameSP
  • The primary key created for a table should be having the key name as pk_TableName
  • The foreign key created for tables should be in the format of fk_TableName_PrimaryKeyReferencingTableName
  • All reserve words used in writing the scripts should always be in ALL CAPS
  • Proper indentation needs to maintained in the scripts, set your system to indent the tabs by 4 spaces
  • Please try to write simple comments in the script related to the business logic for anyone to understand. 

C# Scripting

  • Keep all variables in camel writing format
  • Keep all object variable names as obj<T>
  • Keep all the methods name, parameter name and data type consistent in each layer
  • After creating a method in the DAL, please writer a small summary for that method - explaining what is the reason for writing this method, what are the parameters and the output.
  • Have similar type of methods in code-block regions
  • Apply indentation properly in all levels of the codes
  • In the controllers, please follow the same pattern as the stored procedure for database handling. All controllers in the application should have a similar function name being called

HTML Scripting

  • Keep the html pages formatted properly
  • Write the html code in XHTML, implies that if any html tag does not have a closing tag, add /> to close this tag in the html code

When you are check-in files in the VSS please remove all commented or un-desired codes from the files. If you think its an important or useful piece of code, please enter the code in the blog.

Also as we have purchased the latest version of the Telerik RadControls, please try to read and go through documentation and client-side API. We should try to use these controls in as many ways we can. Telerik controls provides us with greater flexibility and data handling in ajax.

I will over the period of time keep updating this post by adding new points for all of us to be implementing them in our projects.

One of the most important thing that a lot of you are not following is to daily in the morning first check your official email. All tasks or bugs assigned  on a project to you are emailed from the people working on the project or the client itself.

  • Currently 0 /5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

About Us

studio NETSOULS is a complete IT services company, offering strategy, design, development and implementation of the total solution for your web and IT initiatives. The solutions we provide, enables businesses to leverage leading edge technology to gain sustainable competitive advantages in today's marketplace.

We specialize in designing, developing and deploying the next generation of IT solutions including e-business solutions Read more...

Tags

This will be shown to users with no Flash or Javascript.

Contact Us

My status

Quote of the Day

"Do you see a man wise in his own eyes? There is more hope for a fool than for him."

- Proverbs 26:12

NutritionVista

www.NutritionVista.com

Archives


Advertisements


Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Log in