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.



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.



The source code for the project I am testing is located here: incase you wish to try this out yourself.  The assumptions and environment settings are the same as they were in my previous post ( ).

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

Making a Unit Test Framework agnostic Assertion in C#