3

I migrated my existing app over to .NET Core 2 (it was such a pain...), but it looks like everything is working now. However, I noticed that initial load up of the webApp and logging out is very slow. I think in these two scenarios, a .cshtml is being rendered by the server.

I took out applicationInsights which made it a bit snappier, but loading is still slow. I also tried not using kestrel to load my https cert and to just have it be http. That seems to be quicker as well, but I need https to be configured.

Are there any solutions to this? Microsoft documents doesn't seem to have an migration tips on the cshtml files themselves.

EDIT:

I also found this thread: Visual Studio debugging/loading very slow

Not sure how to turn off symbols in VS Code though. Or if that is a related issue.

EDIT2:

I found this in the docs:

Razor view precompilation is currently unavailable when performing a self-contained deployment (SCD) in ASP.NET Core 2.0. The feature will be available for SCDs when 2.1 releases.

Could that be the reason why my view is slow? Is it rendering/loading each time?

EDIT3:

Index.cshtml:

`

@{
    ViewData["Title"] = "MyTitle";
}

<div id="react-app">
     <svg
        class="svg-loader"
        xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 50 50"
        style="width:60px;height:60px;display:block;margin:100px auto">
        <path d="">
            <animateTransform
                attributeType="xml"
                attributeName="transform"
                type="rotate"
                from="0 25 25"
                to="360 25 25"
                dur="0.6s"
                repeatCount="indefinite"
                />
        </path>
  </svg>
</div>

@section scripts {
  @if (ViewData["jwt"]!=null)
  {
    <script>
      var token = '@(ViewData["jwt"].ToString())';
      localStorage.setItem("jwt", token);
    </script>
  }
  <script src="~/dist/app.js" asp-append-version="true"></script>

  @if (ViewData["appInsightKey"]!=null)
  {
  <script>
   var appInsights=window.appInsights||function(config){
    function i(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o="script",s="AuthenticatedUserContext",h="start",c="stop",l="Track",a=l+"Event",v=l+"Page",y=u.createElement(o),r,f;y.src=config.url||"https://az416426.vo.msecnd.net/scripts/a/ai.0.js";u.getElementsByTagName(o)[0].parentNode.appendChild(y);try{t.cookie=u.cookie}catch(p){}for(t.queue=[],t.version="1.0",r=["Event","Exception","Metric","PageView","Trace","Dependency"];r.length;)i("track"+r.pop());return i("set"+s),i("clear"+s),i(h+a),i(c+a),i(h+v),i(c+v),i("flush"),config.disableExceptionTracking||(r="onerror",i("_"+r),f=e[r],e[r]=function(config,i,u,e,o){var s=f&&f(config,i,u,e,o);return s!==!0&&t["_"+r](config,i,u,e,o),s}),t
    }({
        instrumentationKey: '@(ViewData["appInsightKey"].ToString())'
    });

    window.appInsights=appInsights;
    appInsights.trackPageView();
  </script>
  }
}

`

EDIT4:

I narrowed it down to layout.cshtml: The renderBody and section seems to be really slow. I'm going to read up more on it.

`

    @RenderBody()
    <script src="~/dist/vendor.js" asp-append-version="true"></script>
    @RenderSection("scripts", required: false)
</body>

`

EDIT: <script src="~/dist/app.js" asp-append-version="true"></script> It looks like this line is the reason why its slow.

The pages that they are loading have not changed and are the same size. Yet in 1.1 it takes around 8seconds and in 2 it takes 35 seconds. The 1.1 load time wasn't great to begin with, but in 2 its ridiculous.

user6728767
  • 1,123
  • 3
  • 15
  • 31
  • What does your Debugger's Code Profiler say? – Dai Apr 24 '18 at 21:04
  • @Dai When you say Code Profiler, do you mean Visual Studio Code's Debug Console? – user6728767 Apr 24 '18 at 21:05
  • No, I'm referring to the Performance and Profiler features of the .NET debugger in Visual Studio (not "Visual Studio Code" which is a separate product entirely), but I see you tagged your question with VSC so you'll need to see what features are available there that you can use. – Dai Apr 24 '18 at 21:08
  • Are you debugging directly or did you attach to a running server? If you are running your project directly from Visual Studio, it will always be slower at first as JIT compilation takes place, or as the browser caches all the scripts and stylesheets. Try putting your application into a running IIS application pool and run each page at least once in a browser before measuring baseline. You could also compile to native code to avoid JIT completely with 'dotnet build --native' . – Drunken Code Monkey Apr 24 '18 at 22:53
  • Yeah I noticed the pages were faster after navigating around. However, refreshes are still very slow, which leads me to believe its the cshtml rendering. @DrunkenCodeMonkey The `` line seems to be slow. Which is the one loading my project. Is webpack/react known to be slower with .NET Core 2? – user6728767 Apr 24 '18 at 23:07
  • The static files are unchanged and still the same size. Not sure why it would take longer to render. – user6728767 Apr 25 '18 at 03:11
  • [More info here (not a real solution though)](https://developercommunity.visualstudio.com/content/problem/178471/tests-debugging-always-takes-a-long-time-to-load-s.html) – JensG Jan 13 '19 at 13:01
  • any solution for loading fast pages you found ? – Ahmad Jun 06 '20 at 16:46

0 Answers0