views:

195

answers:

6

There's so much hype about ASP.NET MVC these days, but the truth is that ASP.NET webforms is not going anywhere for some time. Is there any way for current developers to optimize ASP.NET webforms to perform as fast as ASP.NET MVC?

I have noticed a significant difference in speed between ASP.NET MVC and ASP.NET webforms. MVC is a lot snappier and loads pages faster than webforms. Can I achieve the same with ASP.NET webforms by optimizing it? If yes, what would you recommend?

+5  A: 

One reason for that is because of ViewState, among other bloated code rendered as part of an <ASP:TextBox>, etc. You should focus on page weight.

Everything else being equal, that is the main performance difference that I'm aware of.

Nate Bross
You don't have to use ViewState or ASP.NET controls, implementation detail.
rick schott
Yes, but most people do, and that is why MVC seems faster, because its not even an option.
Nate Bross
@rick - If you are not using ASP.NET controls or ViewState, you aren't using WebForms. The OP didn't ask about MVC vs working on the bare minimum of ASP.NET.
Richard Szalay
+3  A: 

I have noticed a fairly perceivable difference in speed

Perhaps you should properly measure performance in a definable way first. Then, if you do in fact have a difference it will be much more clear where that difference comes from and how to bridge that performance difference.

qstarin
+1  A: 

Is this a case of two different tools for two different approaches to solving problems and trying to compare between them?

drachenstern
a.k.a. apples to oranges
msarchet
+8  A: 

The technology does not matter, how you implement your application does. One can argue ViewState would make a difference but that is also an implementation detail. ViewState is not required and you can also leave it on the server. At the end of the day both of these technologies deliver HTML over HTTP.

rick schott
... at different speeds. ;)
Jim Schubert
....show me proof with same output
rick schott
Each Framework does introduce some pipeline overhead (MVC has to parse routes, etc. while WebForms has to wire/listen to events, parse controls, etc.). The real question is, is there a measurable different between the overhead of the two Frameworks? If there is, then no amount of user tweaking can get one as fast as the other.
Justin Niessner
+5  A: 

In your page directive do the following:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
    Inherits="TestApp._Default" EnableViewState="false" %>

Mainly turning off ViewState will make up a majority of the difference in page performance. Also limitting the use of WebForm controls will also make your HTML served up a lot less verbose as they tend to produce very verbose HTML.

On the other hand doing so is almost like cutting away some of the large advantages to WebForms. The controls and the abstracting of state by using ViewState is some of the main reason's why WebForms is so popular today.

I do a lot of WebForms development still and do MVC as well. Having knowledge of both and their strengths will help you create a performant app in either framework. When I create any new WebForms app, the first thing I do is to wrap pages in a Panel make sure to disable ViewState for the entire panel. As I develop, and I find a use for the ViewState (eg. to save me time or simplify things) I turn it on case by case so I understand why I am using it and make a consious decision to add the overhead to my page.

WebForms can be just as fast as MVC if you approach your web app with performance in mind but it's very easy to make it much slower if you want to just ignore performance and just get the app done.

Kelsey
+3  A: 

There is this one thing that can make ASP.NET slow that others mentioned: Viewstate. This is especially true for ajax calls. The complete Viewstate is posted when using UpdatePanels.

That said there is this one thing that will make your ASP.NET site outperform your ASP.NET MVC site: Caching. ASP.NET allows for donut caching: you can define caching rules on a WebControll basis. You can not do this in ASP.NET MVC.

If you realy thing you have a speed problem try to find the botttlenecks. It might be database calls (use sql-profiler to check), it might be html-related (use yslow) or it might the application related (try a profiler like the one from redgate ).

Malcolm Frexner
You can cache at the partial view level in MVC and there's nothing preventing you from writing your own cache at other levels of the framework. +1 for mentioning database calls as a performance bottleneck.
Ryan
I don't see how you can cache at a partial level. Check http://haacked.com/archive/2008/11/05/donut-caching-in-asp.net-mvc.aspxBut offcourse you can (and should) cache calls to the database.
Malcolm Frexner