views:

8419

answers:

11

I found some wild remarks that ASP.NET MVC is 30x faster than ASP.NET WebForms. What real performance difference is there, has this been measured and what are the performance benefits.

This is to help me consider moving from ASP.NET WebForms to ASP.NET MVC.

+10  A: 

Rick Strahl has some thoughts on ASP.NET MVC performance in What's Ailing ASP.NET Web Forms.

Espo
@Espo Thank you. A very interesting article, although he doesn't touch on the performance differences between the two.
GateKiller
+3  A: 

The only concrete numbers I can find which are from early ASP.NET MVC-development is on this forum-thread:

http://forums.asp.net/p/1231621/2224136.aspx

Rob Connery himself somewhat confirms statement that ScottGu has claimed that ASP.NET MVC can serve 8000 requests per second.

Maybe Jeff and his crew can give some kind of hint from their development of this site.

Seb Nilsson
+32  A: 

We haven't performed the type of scalability and perf tests necessary to come up with any conclusions. I think ScottGu may have been discussing potential perf targets. As we move towards Beta and RTM, we will internally be doing more perf testing. However, I'm not sure what our policy is on publishing results of perf tests.

In any case, any such tests really need to consider real world applications...

Haacked
Now that MVC has been released, is there any update on releasing the perf results?
chris
Just voting this up because the 5,999 rep score before was hurting my eyes :(
Damien
By this time, you must surely have some numbers. Care to update your answer? Or did you find that the pesky policy forbids it?
tvanfosson
The number is 42. :) In general, our numbers will probably be useless to real world apps so we as a rule don't give them out. However, I know of other teams at Microsoft building large scale websites who show favorable numbers. In other words, any perf issues are more likely going to be due to programmer mistakes than any inherit issues in the framework. Typically interactions with the database and external services are the culprits. :)
Haacked
+25  A: 

It decreased one of my pages from 2MB payload, to 200k, just by eliminating the viewstate and making it bearable programatically to work with the submitted output.

The size alone, even though the processing was the same will create vast improvements in connections per second and speed of the requests.

DevelopingChris
you could have fixed that pesky large viewstate without MVC too
Andrei Rinea
Just to elaborate ViewState can be turnd off @ page level or in web.config
bbqchickenrobot
yes but in mvc its a sane default not a design decision that forces you to leave all controls and the vendors that claim to just work on web forms, by making web forms "mis behave" by removing its back bone. I don't disagree you could just recode that page, but the whole app was better without viewstate.
DevelopingChris
+1  A: 

There's really no way to answer this. MVC uses the Web Forms view engine by default itself, and can be configured to use any number of custom view engines, so if you want a performance comparison you'll have to be more specific.

Gerald
+8  A: 

My testing shows something between 2x and 7x more req/sec on MVC, but it depends how you build your webforms app. With just "hello world" text on it, without any server side control, mvc is around 30-50% faster.

Hrvoje
+3  A: 

For me the real "performance" improvement in MVC is the increase the testable surface of the application. With WebForms there was a lot of the application that was hard to test. With MVC the amount of code that becomes testable basically doubles. Basically all that isn't easily testable is the code that generates the layout. All of your business logic and data access logic -- including the logic that populates the actual data used in the view -- is now amenable to testing. While I expect it to be more performant as well -- the page life cycle is greatly simplified and more more amenable to web programming -- even if it were the same or a little slower it would be worth switching to from a quality perspective.

tvanfosson
I would truly love to know why someone downvoted this answer.
tvanfosson
+29  A: 

I think this will be a hard question to definitively answer as so much will depend on A) how you implement the WebForms application, and B) how you implement the MVC application. In their "raw" forms, MVC is likely faster than WebForms, but years and years of tools and experience have produced a number of techniques for building fast WebForms applications. I'd be willing to bet that a senior ASP.NET developer could produce a WebForms application that rivals the speed of any MVC application- or at least achieve a negligible difference.

The real difference- as @tvanfosson suggested- is in testability and clean SoC. If improving performance is your chief concern, I don't think it's a great reason to jump ship on WebForms and start re-building in MVC. Not at least until you've tried the available techniques for optimizing WebForms.

-Todd

Todd
+17  A: 

I think that many of the people who think that WebForms are inherently slow or resource intensive are placing the blame in the wrong place. 9 times out of 10 when I am brought in to optimize a webforms app there are way too many places where the apps authors misunderstand the purpose of the viewstate. I'm not saying that the viewstate is perfect or anything, but it is WAY too easy to abuse it, and it is this abuse that is causing the bloated viewstate field.

This article was invalueable in helping me understand many of these abuses. http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/truly-understanding-viewstate.aspx

In order to make a valid comparison between MVC and WebForms we need to be sure that both apps are using the architectures correctly.

Ariel
A: 

I started out work in MVC about a year ago, I was inspired but not impressed.

I loath the view state and see it as the root of all evil in terms of ASP.NET. This is why I just don't use it and to be perfectly honest why would you?

I took basically the ASP.NET MVC Framework concept and built that in my own way. I changed a couple of things though. I built my controller wrapping code, or URL routing code around dynamic recompilation.

Now, I would go as far as to say that ASP.NET MVC applications will be faster based on how you use it. If you completely abandon WebForms you'll be faster becuase the ASP.NET life-cycle and object model is humongous.

When you're writing you're instantiating an army... no wait, a legion of objects that will participate in the rendering of your view. This is gonna be slower than if you where to express the minimal amount of behavior in the ASPX page itself. (I don't care about view engine abstraction because the support for ASPX pages in Visual Studio is decent, but I've completely dropped WebForms as a concept and basically any ASP.NET framework due to code bloat or not being able to change the things that wire my application).

I've found ways of relying on dynamic recompilation (System.Reflection.Emit) for emitting special purpose objects and code whenever needed. The executing of this code is faster than reflection but initially built through the reflection service. This has given my MVC flavored framework great performance but also very statically typed. I don't use strings and name/value pair collections. Instead my custom compiler services goes in a rewrites a form post to a controller action being passed an reference type. Behind the scene there is a lot of things going on but this code is fast, a lot faster than WebForms or the MVC Framework.

Also, I don't write URLs, I write lambda expressions that get translated into URLs that later tell which controller action to invoke. This isn't particularly fast but it beats having broken URLs. It's like if you had statically typed resources as well as statically typed objects. A statically typed web application? That is what I want!

I would encourage more people to try this out.

John Leidegren
How fast does your car go? Well let me tell you about my truck that I built...
jfar
So this is not an direct answer to the question? It's however related, and it makes a couple of good points. But hey, it's something I built for my own needs, and it suits me perfectly fine. I also enjoy sharing my ideas, even if very few people understand why.
John Leidegren
Well it doesn't answer the question, downvote stays.
jfar
Well, you don't have to change your vote, but you don't have to put a down vote on it, because it is not 'the' answer. If you take a while a look into the text there's several things that points to ASP.NET MVC being faster than WebForms and why that's the case. And it boils down to things like reflection and the object model and ViewState overhead of WebForms.
John Leidegren
@John - now that MVC2 is out with improved model binding, validation, strongly-typed helpers, etc., how you would evaluate it compared to your method?
tvanfosson
MVC2 is a lot better, I believe it has pretty much replaced what I was building at the time (with MVC1 in beta). I ran into quite the ordeal of problems in relation to what I was trying to build on top of ASP.NET without opting out of the existing tooling. Sufficient to say, I learned a lot and eventually brought this into production. I now realize that the current tooling/framework (VS/ASP.NET/C#) isn't really fit for this stuff and eventually if you wanna go down this road, you'll need to invest in your own compilers/model-checking stuff for some things to work in your favor.
John Leidegren
I didn't think much of ASP.NET MVC at that time. It lacked things I knew I wanted. But, I had to spend a lot of time developing, testing and figuring these things out. I still think that the static aspect of the web framework I was building is superior to MVC in that regard but the C# compiler is inefficient for solving that problem. You need some language/compiler that allows greater flexibility when it comes to meta programming. I had to do a lot of that at runtime and it was often impossible to cache compiled instances so I had to dynamically recompile things a lot.
John Leidegren
I ended up building a lot of code generation tools as well to make it play nice with the database. I was using Linq-to-Sql and the tooling that ships with Linq-to-Sql was pretty much useless. I used simple naming conventions to model type enumerations, entities and associations and then mapped that in the attribute meta model way of Linq-to-Sql. Though, in the end I had a very elegant declarative model. In which things like data binding, validation and CRUD was pretty much done automatically.
John Leidegren
I had great fun and went through great pain to see this through. Though what I ended up realizing is that this statically typed web, it requires that you push work into code generation and dynamic compilation so that you can work you way forward in a declarative manner. I believe this is a trend that you see showing up in more and more places.
John Leidegren
+3  A: 

I think the problem here is that no matter how much faster ASP.Net MVC is than the old webforms, it won't make a difference, because most of the time taken is in the database. Most of the time, you web servers will be sitting at 0-10% CPU usage just waiting on your database server. Unless you get an extremely large number of hits on your website, and your database is extremely fast, you probably won't notice a big difference.

Kibbee
Your users might - no viewstate.
UpTheCreek