ASP.NET MVC rendering seems slow

I created a completely new MVC4 web application in Visual Studio and did nothing more with it than added the home controller and the Hello world index to it. Then I installed the MiniProfiler NuGet package and placed the desired pair of lines in _Layout.cshtml . This is what I get when I launch a site in release mode (hosted in IIS):

MVC rendering picture

Rendering time varies with pageload, but 130 ms is about as fast as it gets. This seems a little slow to me, as I have seen other people who get pages done in 30 ms or faster. Any ideas why rendering would be so slow with the new empty MVC4 project? My processor is Intel Core i5-2400, and on the device - 16 GB.

By the way, this is not the first time a page loads; I reloaded the page several times before getting this result in 130 ms.

UPDATE:
I followed the advice in response from PSCoder (deleted everything except RazorViewEngine), and halved the rendering time by half:

MVC rendering picture 2

This is really good, but I still get about 70 ms or higher for the main Render action on the page; Ideally, I would like to do it twice or better.

In particular, I would like to ask:

  • Is this rendering time too slow or average for my machine?
  • Is there any way to speed it up?
+44
performance c # asp.net-mvc asp.net-mvc-4
Apr 29 '13 at 14:35
source share
2 answers

This may help improve the performance problem of ASP.NET MVC, but one performance improvement you can make is to clear all view engines and add the ones you use. let's say for ex: - RazorViewEngine . MVC registers the 2 default Webforms and Razor view engines, so cleaning and adding those that are used on their own will improve search performance.

You can add this to global.asax Application_Start .

  ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine()); 

To take full advantage of view caching, and thus again, the performance gain will compile the code in release mode and make sure your web.config configured using <compilation debug="false" /> to look to find the caching for input.

+72
Apr 29 '13 at 14:42 on
source share

Adding @PSCoder to the response - we always check only `.CSHTML files

 ViewEngines.Engines.Clear(); IViewEngine razorEngine = new RazorViewEngine() { FileExtensions = new string[] { "cshtml" } }; ViewEngines.Engines.Add(razorEngine); 

Also, make sure you work in Release Mode - this is absolutely important, because ASP / Razor / MVC uses pretty aggressive caching when in release mode

<compilation targetFramework="4.0" debug="false"> in your Web.Config file.

Sam Saffron / Qaru also looked at rendering performance:

http://samsaffron.com/archive/2011/08/16/Oh+view+where+are+thou+finding+views+in+ASPNET+MVC3+

+54
Apr 29 '13 at 16:32
source share



All Articles