1

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

2
  • On which version of IIS are you hosting your application? Commented Sep 25, 2012 at 13:24
  • It doesn't matter - read D. Ward's article mentioned below. Commented Sep 25, 2012 at 13:30

2 Answers 2

2

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").

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, I'm using this, but strangely things aren't as instant as you'd expect (that could be another issue).
You could bring that a step further by writing a custom IProcessHostPreloadClient provider as shown in the ScottGu's post inside which you could do heavy initialization work and warmup the application.
I thought about that, but is there anyway to iterate all the views and load them all...
1

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.

5 Comments

Thanks - Don't worry, I've read over the @SamSaffron blog post about views being slow, and I've included my very own "Big Pink Box(TM)" method which checks for Http debugging etc.. so I know we're running in 'Release'/Retail mode
Thanks for that - that's all good and well, but it's the FIRST view lookup that is the problem
Based on your updated question, you've already done all that I know of to optimize view location. If there are other options, I'd like to know as well!
Darin's answer regarding AutoStart looks promising.
I'm thinking about writing a quick and dirty bit of code that will iterate the views folder and call render on the views (hopefully). I'll try share if I can!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.