Friday, April 21, 2006

.NET ViewState and Most 3rd Party Components - Are a pain

  • Since I started using .NET 1st problem I discovered is - ViewState. People misused it and it grows like hell for most of the .NET apps I see on the web
  • I went to a company that was planning to launch a web based file synchronization tool. They boasted about their technology and blah blah. I asked them to show their app. It took a bit of time. I was curious that when they said that performance is great and so on.. then why the page is taking so much of load time? I asked them whether I can view the source of the rendered page by clicking on View Source? You know what I discovered? Page size was 1 MB - 500kb of Viewstate and 500kb of rest of the page? They had a treeview display of the folder structure of the hard drive in treeview and on every postback recreated the treeview. Even then they didn't take care of turning the viewstate off. I've notice that most of the people spend lots of time for performance tuning in areas where the difference might be in a few milliseconds - but they don't think of these things. One of the biggest disadvantage of having huge viewstate is - every postback and refresh of page means this Input variable is posted back to the server and rendered back to the browser. So it takes up lots of bandwidth resulting in overall scalability loss.
  • I hate most of the 3rd party components for .NET. They render so much amount of data on the client side that I tend not to utilize most of them. For example, in one of my recent assignments client insisted on showing a TreeView like structure using ComponentArt component only. This tree structure was displayed in a GridView control with 4-5 entries for each row. When I did some profiling, I found that for every treeview all the settings were also going in the viewstate, were also being rendered in the browser and hence making each row have 5kb of extra html and viewstate! Isn't it too much for just 5 lines? Since most of the settings are related to CSS display, isn't it better to provide a CSS file to be included and just store the CSS file path? For example, for calendar picker, I use http://www.dynarch.com/projects/calendar/ embedded in a user control. On the client side, it requires only minimum amount of javascript rendered. Everything is an include file. It improves performance a lot.

No comments: