Performance while Rendering Pages ASP.NET MVC

4

How can I get more performance to render my pages using ASP.NET MVC?

    
asked by anonymous 08.08.2014 / 22:08

1 answer

5

The render performance of a View is related to a number of aspects:

  • Controller performance;
  • Number of Filters and Interceptors Involving Your Application;
  • Amount of JavaScript placed in View and in Layout of View .

There is no road map to improve performance that is canonical, but I can try to put together a number of measures to improve the performance of your Views :

1. Remove% with% that will not be used

In your ViewEngines file, use the following commands:

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

In this case, you will only use Razor. If you are using WebForms, use:

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

2. Force use of Global.asax.cs for static pages

For example:

public class HomeController : Controller
{
    [OutputCache]
    public ActionResult Index()
    {
       return View();
    }
}

If the page changes slightly, caching it may be a good solution to avoid using the rendering engine when this is not necessary.

3. Removing Debug information from Views in Production

When you publish your system in production, make sure your [OutputCache] has noted the following:

<compilation targetFramework="4.0" debug="false"> 

4. Use Eager Load for Web.config that use lots of dependent information

This is valid for systems that use some lazy load framework ( Lazy Load ), such as the Entity Framework and nHibernate.

For example, if I load a Person (usually an entity with lots of aggregate data), I should rush the load of information, preventing Lazy Load from causing a performance bottleneck.

var pessoa = context.Pessoas.Include(p => p.Enderecos)
                            .Include(p => p.Telefones)
                            .Include(p => p.Compras)
                            .Include(p => p.Dependentes)
                            .Single(p => p.PessoaId == pessoaId);
    
08.08.2014 / 22:21