Performance to Render ASP.NET MVC Pages

Asked

Viewed 121 times

4

How can I have greater performance to render my pages using ASP.NET MVC ?

1 answer

5


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

  • Controller performance;
  • Amount of Filters and Interceptors involving your application;
  • Amount of Javascript placed on View and in the Layout of View.

There is no roadmap to improve canonical performance, but I can try to gather in this response a number of measures to improve the performance of your Views:

1. Withdraw ViewEngines that will not be used

In your file Global.asax.cs, use the following commands:

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

For this case, you will only use Razor. If you are using Webforms, use:

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

2. Force the use of [OutputCache] for static pages

For example:

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

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

3. Remove Debug Information from Production Views

When publishing your system in production, make sure that your Web.config have noted the following:

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

4. Use Eager Load for Views who use a lot of dependent information

This is valid for systems using some lazy load database framework (Lazy Load), such as the Entity Framework and nhibernate.

For example, if I carry a Person (usually an entity with a lot of aggregated data), I must hasten the load of information, preventing the Lazy Load cause a bottleneck in performance.

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);
  • Because of debug="false"?

  • debug="false" removes the Debug information, which consumes some processing to be included in the request.

  • @Ciganomorrisonmendez when compiling in "release" he already puts debug=false no?

  • Depends on configuration. If Web.config undergoes transformation, yes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.