Los Techies : Blogs about software and anything tech!

Performance differences in the ASP.Net MVC View Engine when using two View Engines versus a single Composite View Engine.


 

While I was testing out my VirtualPathProvider implementation in the Opinionated Input Builders series I ran across an interesting performance difference which was quite surprising.  In fact even after looking at the source code to the MVC ViewEngineCollection it still seemed like this difference should not occur.  But it does and I am sure that we will get to the bottom of this. 

Don’t go jumping to any conclusions just yet about how this performs because the one common piece of functionality that these engines still rely on is a VirtualPathProvider that I implemented and I can honestly say I understand very little about how the VPP is used and how to ensure that it was implemented correctly to ensure maximum performance.

The first part of this graph (the green line) shows the requests / second that I can get through my MVC view when using two ViewEngines, the default view engine to handle all requests to the /Views/{controller} and /Views{Shared} . The second view engine Handles all requests to my virtual path /Views/InputBuilders/ .  At the 7:50 mark I changed the flag and recompiled the application.  You see a small dip while the application restarts with the new code in place.  Now the application uses a single view engine that handles all the views for the default locations and my extra virtual path.

image 

 

Here is the part of my codebase that shows the difference between adding my ViewEngine to the collection and Clearing the Collection and adding the view engine with parameters to handle the additional view locations.

 

image

The source code for the project I am testing is located here: http://code.google.com/p/erichexter/downloads/detail?name=InputBuildersV4.zip&can=2&q=#makechanges incase you wish to try this out yourself.  The assumptions and environment settings are the same as they were in my previous post ( http://www.lostechies.com/blogs/hex/archive/2009/06/13/opinionated-input-builders-part-6-performance-of-the-builders.aspx ).

I would love to hear from someone who has an eye for performance tuning!

Kick It on DotNetKicks.com
Posted Jun 18 2009, 10:01 PM by erichexter
Filed under: , , , , , , ,

Comments

David Ebbo wrote re: Performance differences in the ASP.Net MVC View Engine when using two View Engines versus a single Composite View Engine.
on 06-19-2009 12:17 AM

Eric, I'm almost sure that the issue is what I mentioned by email.  When you use multiple view engines, the caching in the primary view engine gets disabled (which I think is an MVC bug).  Hence on every request, it tries a bunch of lookups before finding your view.  You can see this easily in the debugger, by breaking on all exceptions (and disabling Just My Code).  With single engine, you won’t get any exceptions (after the first request, which warms up the cache).  With double engine, you’ll get:

- The file '/Views/Home/DateTime.aspx' does not exist.

- The file '/Views/Home/DateTime.ascx' does not exist.

- The file '/Views/Shared/DateTime.aspx' does not exist.

- The file '/Views/Shared/DateTime.ascx' does not exist.

- The file '/Views/Home/DatePicker.aspx' does not exist.

- etc…

Reflective Perspective - Chris Alcock » The Morning Brew #372 wrote Reflective Perspective - Chris Alcock » The Morning Brew #372
on 06-19-2009 3:25 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #372

Performance differences in the ASP.Net MVC View Engine when using … wrote Performance differences in the ASP.Net MVC View Engine when using …
on 06-19-2009 7:03 AM

Pingback from  Performance differences in the ASP.Net MVC View Engine when using …

Performance differences in the ASP.Net MVC View Engine when using … wrote Performance differences in the ASP.Net MVC View Engine when using …
on 06-19-2009 7:04 AM

Pingback from  Performance differences in the ASP.Net MVC View Engine when using …

DotNetShoutout wrote Performance differences in the ASP.Net MVC View Engine when using two View Engines versus a single Composite View Engine. - Eric Hexter - Los Techies
on 06-19-2009 7:04 AM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Victor Kornov wrote re: Performance differences in the ASP.Net MVC View Engine when using two View Engines versus a single Composite View Engine.
on 06-19-2009 10:31 AM

Hey Eric,

have you tried to use one composite view negine instead of 2 separate? I.e. you build a vieww engine that delegates to the appropriate web forms or your own InputBuilderViewEngine.

erichexter wrote re: Performance differences in the ASP.Net MVC View Engine when using two View Engines versus a single Composite View Engine.
on 06-19-2009 11:35 AM

@Victor, The single view engine is acting as a composite through inheritance.

@David, In order to attach the debugger don't you have to take the debug="false" out of the web.config?  If so than the Caching is turned off and as a result the "more performant" path for the code is not executed. So I guess the next thing to try is to pull down the source for MVC 1.0 make a change to the force the cache to work in debug=true to determine if the exceptions are the problem or the querying of each viewEngine in cache is causing the degradation of performance.

Performance differences in the ASP.Net MVC View Engine when using … | Webmaster Tools wrote Performance differences in the ASP.Net MVC View Engine when using … | Webmaster Tools
on 06-19-2009 1:11 PM

Pingback from  Performance differences in the ASP.Net MVC View Engine when using … | Webmaster Tools

David Ebbo wrote re: Performance differences in the ASP.Net MVC View Engine when using two View Engines versus a single Composite View Engine.
on 06-19-2009 2:35 PM

Eric, the trick is to start VS without debugging (Ctrl-F5), and later attach to the process (Ctrl-Alt-P).

Frankly, I hate that MVC changes its caching behavior based on the debug flag.  It should be a separately controlled thing.  I'll ask the team to fix that in the next version.

erichexter wrote re: Performance differences in the ASP.Net MVC View Engine when using two View Engines versus a single Composite View Engine.
on 06-19-2009 2:50 PM

@David, in that case than it seems .. for now.. a composition based View Engine is the best approach, as I have discovered by persistence.  Thanks for the clarification.

Daily Links for Saturday, June 20th, 2009 wrote Daily Links for Saturday, June 20th, 2009
on 06-20-2009 7:31 AM

Pingback from  Daily Links for Saturday, June 20th, 2009

progg.ru wrote Разница в ASP.Net MVC при использовании двух View Engine вместо одного
on 06-21-2009 6:05 AM

Thank you for submitting this cool story - Trackback from progg.ru

ASP.NET MVC Archived Blog Posts, Page 1 wrote ASP.NET MVC Archived Blog Posts, Page 1
on 06-22-2009 12:50 AM

Pingback from  ASP.NET MVC Archived Blog Posts, Page 1

Copyright Los Techies 2008, 2009. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems