Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Render Speedup

I just hooked up the mvc-mini-profiler (thanks SO!) on my site and was looking around to see how well I've done up to this point (it's my first major bout with linq to entities and mvc). So far everything is looking good, however I'm always looking for ways to improve response times. At this point it looks like the only major boost I could get would be from reducing the time it takes to render the individual views on each of my pages.

profiler screeny

You can see from my screeny that the rendering of the Blog view is the longest running task. I know that 30ms is already really quick, but I'm betting there are still some tricks I can pull to get these numbers even lower.

So the question is this: How can I reduce view render times? I know that caching of dynamic views into something like the HttpRuntime.Cache can help, but I'm even seeing several ms durations for static view rendering. What techniques do you use to lower the render times of your views?

like image 597
JesseBuesking Avatar asked Dec 16 '11 04:12

JesseBuesking


People also ask

Why is MVC faster?

Faster development process:MVC supports rapid and parallel development. If an MVC model is used to develop any particular web application then it is possible that one programmer can work on the view while the other can work on the controller to create the business logic of the web application.


1 Answers

I suggest 2 things (if you don't have it done yet)...

  1. Remove unused ViewEngines. So if your project uses only the razor view engine, do this in the global.asax on Application_Start();

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

    or

    ViewEngines.Engines.Add(new WebFormViewEngine());
    

    if you use the WebFormsViewEngine only

  2. The biggest improvment is to use the OutputCacheAttribute to cache the html. I dont think your Blog changes on every Request ;)

    public class BlogController : Controller
    {
        [OutputCache]
        public ActionResult Index()
        {
           // do something here
           return View();
        }
    }
    

You can set the cache-duration and more. Check out: MSDN - OutputCacheAttribute.

like image 109
dknaack Avatar answered Sep 18 '22 13:09

dknaack