Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is occurring in the Render step in Miniprofiler?

Miniprofiler is showing me that the slowest part of my page is the "Render" step (attached screenshot below).

What is occurring in that Render step? Is it the stage when your .aspx is converted into html to be sent to the client? Is there anywhere that I can add Miniprofiler.Current.Step() to see exactly why it is slow?

The app is MVC4 on .NET4.5 with the .aspx render engine.

enter image description here

EDIT:

The controller action is just standard MVC stuff along the lines of:

public ActionResult Index()
{
    ViewData["foo"] = GetFoo();
    return View(model);
}

And the ASPX view is basic stuff like:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
    Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <p><% ViewData["foo"] %></p>
    <% Html.RenderPartial("Something", Model) %>
</asp:Content>
like image 567
JK. Avatar asked Nov 02 '22 12:11

JK.


1 Answers

First a ViewResult Object is generated when you call the View() Method.

This looks like

return View( Model );

Next the Render Step happens when the ExecuteResult() method is called in a ViewResult Object; Generating an HTML document that is sent to the client's browser.

The ExecuteResult() Method (Render) process involves:

  • Rendering HTML elements and JQuery/*Javascript* attributes in place of your Helpers
  • Model Binding to your View;; Each Helper and Model reference is replaced with Values from your Model and/or ViewBag.
  • Merging your View with any layout
  • Rendering your Partials

This last part, Rendering your Partials, is like a recursive version of the creating the ViewResult Object. A PartialView(), RenderPartialView(), or Action() Method is executed creating a PartialViewResult Object. This new Result Object also has a ExecuteResult() method which generates an HTML "sub-document" to merge with the "Parent" HTML Document.

Partial View rendering takes even longer if the Partial View has a child Action (Controller Method) associated with it because it carries the burden of instantiating another controller...

You use 2 partial Views; The time to render the partial views combines to 16.1 ms out of 37.1 ms (43% of total time).

Note about ASPX View Engine:

I would bet that the aspx engine takes longer to render views than the Razor engine. The aspx engine

  • has more content (much of it antiquated webforms remnants)
  • I don't believe the ASPX engine has evolved since MVC 3 development began (late 2010), so it is probably less efficient.

In Conclusion:

Rendering Views (ExecuteResult()) can be fairly time consuming compared with Route Engine resoluton (4.5 ms) and Controller instantiation (7.3 ms).

In your case, the time to render your partials and parent views seems high. But I haven't used mini-profiler to check myself.

It could be that your ASPX View Engine is THAT inefficient, or you may have Child Actions associated with your partials that are making heavy database calls...

like image 147
Dave Alperovich Avatar answered Nov 08 '22 04:11

Dave Alperovich