Why do my asp.net views take so long to render?

I’ve optimized my database queries with indexes and am caching output for 10 minutes at a time, but occasionally I have to recalculate the page, and it’s taking way longer than I like. Tools like firebug only show that the request spent a long time waiting on the server. What I really need is a tool to help me locate the bottleneck.

Enter Glimpse, an open-source tool to analyze load times end-to-end for C# asp.net applications. It times everything from javascript, web requests, controller actions, view rendering, database queries, ajax calls, and more.

2016-08-09 07_23_06-Window.png

This image shows that the total time to render the page was 478ms. Of that, 351ms was spent server-side, and 198ms of that was on rendering the view. That means not the database access, but compiling the cshtml with embedded C# at runtime.

How to reduce that render time? Precompile the views at build time!

Now that the views are precompiled, our page render time has dropped to 208ms, with only 72ms spent server side. At 208ms, page loads feel almost instant, which only happens when we have a cache miss once every ten minutes.
2016-08-09 07_30_02-Window.png


Now read this

Building Blocks of the C# ASP.NET MVC Web Stack

Summary # The ASP.NET web stack is Microsoft’s mature platform for creating feature-rich, powerful web applications. Rather than explaining how to write code for the ASP.NET stack, this article intends to walk through each of the major... Continue →