Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC rendering seems slow

I've created a brand new MVC4 web application in Visual Studio, and done nothing more with it than add a Home controller and a "Hello world" index view for it. I then installed the MiniProfiler NuGet package and put the necessary couple of lines in _Layout.cshtml. This is what I get when I run the site in Release mode (hosted in IIS):

MVC rendering picture

The rendering time varies by pageload, but 130ms is about as fast as it gets. This seems a bit slow to me, as I've seen other people who get pages rendered in 30ms or quicker. Any ideas why the rendering would be this slow with a brand new empty MVC4 project? My processor is an Intel Core i5-2400 and the machine has 16GB RAM.

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

UPDATE:
I followed the advice in the answer from PSCoder (remove all but the RazorViewEngine), and it halved the rendering time:

MVC rendering picture 2

This is really good, but I still get about 70ms or higher for the main Render action of the page; ideally I'd like to halve that or better.

Specifically, I'd like to ask:

  • Does this rendering time seem overly slow or is it average for my machine?
  • Is there any way I can speed it up?
like image 847
Jez Avatar asked Apr 29 '13 14:04

Jez


People also ask

Why is my asp net site so slow?

There can be numerous reasons why . NET applications can be slow. These include incorrect memory sizing, GC pauses, code-level errors, excessive logging of exceptions, high usage of synchronized blocks, IIS server bottlenecks, and so on.

Why MVC is faster than ASP Net?

MVC provides better support to TDD (Test driven development). TDD is related to the test first programming concepts of extreme programming. It helps us to reduced time in reworks and helps create loosely coupled code. MVC enforces separation that reduces complexity of project structure.

Is MVC good for performance?

Simply put, MVC helps with website performance optimization. One of the key differentiators when working with MVC is that, unlike older technologies like Web Forms, you have full control over the HTML output.


2 Answers

This could help improve ASP.NET MVC related performance issue , one performance improvement that you can do is to clear all the view engines and add the one(s) that you use. say for ex:- RazorViewEngine. MVC registers 2 view engines by default Webforms and Razor view engines, so clearing and adding the ones that is used alone will improve the look up performance.

You can add this in global.asax Application_Start.

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

In order to completely utilize view look up caching and thus again performance gain compile the code in release mode and make sure that your web.config file is configured with <compilation debug="false" /> for view look up caching to kick in.

like image 135
PSL Avatar answered Sep 21 '22 06:09

PSL


Adding to @PSL 's answer - we only ever check for `.CSHTML files

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

Also, make sure you are running in Release Mode - that is absolutely critical, as ASP/Razor/MVC 'applies some pretty aggressive caching' when in release mode

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

Sam Saffron/Stack Overflow looked into view rendering performance also:

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

like image 24
Stuart.Sklinar Avatar answered Sep 19 '22 06:09

Stuart.Sklinar