user60456
user60456

Reputation:

Are nested layouts in Razor slow?

I have a pretty straight forward nested layout.

When I use _Layout the render time of a page (as shown by MiniProfiler) is about 66ms. Oddly enough, when I use _2ColLayout that jumps to 250ms. The HTML isn't that complex. Am I crazy, or has anyone else seen this? Is there a known work around?

I removed some of the static HTML to clean up the snippets below. I doubt those matter as they are just list-items, anchors, images and stuff.


_Layout

<head>
    @this.InitClientTimings()
    <title>@Page.Title</title>
    @this.TimeScript("Content Bootstrap.css", @<link  href="@Url.Content("~/Components/bootstrap/bootstrap.css")" rel="stylesheet" type="text/css"/>)
    @this.TimeScript("GoogleFont.css", @<link href='http://fonts.googleapis.com/css?family=Days+One|Open+Sans:400&subset=latin,latin-ext' rel='stylesheet' type='text/css' />)
    @this.TimeScript("Content Site.css", @<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />)
   
    @this.TimeScript("LAB.js", @<script type='text/javascript' src="/scripts/LAB.min.js"></script>)
    <script type="text/javascript">        window.q = []; window.$ = function (f) { q.push(f); };</script>
   
</head>
<body id="bootstrap-js">
    <div class="navbar navbar-fixed-top">
        <div class="navbar-inner">
            <div class="container">
                <div class="nav-collapse">
                    <ul class="nav">
                       <!-- nav links -->
                    </ul>
                </div>
               <span class="pull-right">@Html.Action("LogOnControl", "Home")</span>
            </div>
        </div>
    </div>
    <div class="container">
        <div class="page-header">
            @RenderSection("pageheader", false)
        </div>
        <div class="row">
            @RenderBody()
        </div>
    </div>
    <footer>

    </footer>

    @RenderSection("scripts", false)
    @MiniProfiler.RenderIncludes()
    <script type="text/javascript">        $(function () { $("img.lazy").lazyload({ threshold: 50 }); $(window).scroll(); });</script>

     <script type="text/javascript">
         $LAB
        .script("http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js").wait()
        .script("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/jquery-ui.min.js")
        .script("http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js")
        .script("/scripts/jquery.lazyload.min.js")
        .script("/Scripts/social-endlessPage.js")
        .script("/Components/bootstrap/js/bootstrap.min.js")
        .wait(function () {
            $.each(q, function (index, f) {
                $(f)
            });
        });
    </script>
</body>

_2ColLayout

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section pageheader
{
    @RenderSection("pageheader", false)
}
<div class="span8">
    @RenderBody()
</div>
<div class="offset1 span3 rightbar">
    @if (IsSectionDefined("rightbar"))
    {
        @RenderSection("rightbar", false)
    }
    else
    {
       <!--default right bar stuff -->
    }
</div>
@section scripts
    {
    @RenderSection("scripts", false)
}

Upvotes: 3

Views: 769

Answers (1)

user60456
user60456

Reputation:

You know what, nevermind.

In the part I cut out (figures!) I have a call to the Azure distributed cache. Turns out new-ing up a cache client takes 200 ms!...Im surprised at that.

Anyway, fixing that solved it

Upvotes: 1

Related Questions