Asp.net mvc performance questions (partial views and html helpers)

I'm just wondering how much performance you will lose by using a lot of partial views and html helpers in an asp.net mvc application.

As I know html helpers should be lightweight, but I don't see them rendering as fast as if you just created straight html.

Don't get me wrong. I love them, but just wonder how much they will impact your site. I guess not much, but some of these html helpers can get complicated and do quite a bit.

Also I like to use partial views as many of my parts of my site need basically the same code, so you can try to eliminate duplicate code as well, so I like to put it in partial views.

What is the performance impact of Partial Views?

+2


source to share


4 answers


I have no evidence to support this, but I would hardly accept it. Especially for HTML Helpers is just an extra method call. You can copy and paste the code from the helper into the view and you would only execute one method on the stack.



+2


source


I generally agree that there is almost no overhead and that this will be a premature optimization. However, there are two important exceptions that you should be aware of:

  • Using a large number of partial views will be very slow if the ASP.NET compiler only compiles in debug mode . In debug mode, MVC does not cache the location of the files, so it must check every time it renders the view. Don't be fooled! This issue disappears in release mode.

  • There are some "strongly typed" HTML helpers in the MVC Futures assembly for MVC 1.0, which are (1) about 10 times slower than the helpers in the System.Web.Mvc assembly, and are (2) probably incompatible (syntactically ) with (presumably improved from POV performance) the "strongly typed" helpers included in MVC 2. I'd suggest staying away from them.



But in general I agree: write the correct code first, then the profile.

+2


source


Your server hardware and network infrastructure will be more of a limiting factor than html helpers and partial views. Don't think about it.

+1


source


This is a premature optimization. Write it first, then profile it, and if you find the performance is not up to your requirements / SLA, use the profiling tools to find poorly executing code. It probably won't be html helper methods, it will be things like database calls and other cross process calls.

0


source







All Articles