Stuart.Sklinar
Stuart.Sklinar

Reputation: 3761

MVC FindView slow on application start

Is there anyway to run through the application and pre-populate the MVC ViewCache to eliminate the 2sec time loss that can sometimes occur during the warm-up of a web app?

At current whilst our application is starting, we sometimes are greeted with 2sec performance lag times.. once it's started there are mere-milliseconds.

In case it helps, I am definitely running in release mode, and only use the Razor engine:

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        Bootstrapper.Initialise(); //IOC Setup
        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);

        //Only use the RazorEngine. - http://blogs.msdn.com/b/marcinon/archive/2011/08/16/optimizing-mvc-view-lookup-performance.aspx
        ViewEngines.Engines.Clear();

        IViewEngine razorEngine = new RazorViewEngine() { FileExtensions = new string[] { "cshtml" } };

        ViewEngines.Engines.Add(razorEngine);
    }

Any suggestions welcome.

Ta

Upvotes: 1

Views: 1107

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

You could use the new ASP.NET AutoStart feature in IIS 7.5. Also make sure that when you deploy your application it is running in Release mode (debug="false").

Upvotes: 2

jrummell
jrummell

Reputation: 43067

Dave Ward discusses this and other issues related to debug="false" in your web.config in A harsh reminder about the importance of debug=”false”.

In debug mode, view resolution is optimized for ease of development. MVC iterates through the view resolution process each and every time your code renders a named view. That’s helpful since you obviously do want the environment to respond immediately to your changes when you’re working on a site.

In release mode, however, MVC’s view resolution is optimized for performance. When a view location is successfully resolved in release mode, MVC caches the result of that lookup and doesn’t need to perform another filesystem search when it encounters a reference to that named view again.

Upvotes: 1

Related Questions