17

We are having serious issues in the startup (boot) time of our application.

After carefull investigation we have discovered that the most time is consumed by first-time-visit compilation of the cshtml files. This compilation can take up to 50 seconds per cshtml file.

We use Helix architecture with a lot of components. The combination of all those compilations takes ages and it can take up between 20 and 30 minutes for the site to boot. Once all cshtml have been hit once, the site speed and performance is ok.

Example: this cshtml takes 43 seconds to compile!

@using Sitecore.Mvc
@inherits System.Web.Mvc.WebViewPage
@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<Feature.PageLayout.Models.PageSectionViewModel>

@{
var sectionClasses = Model.Presentation.BackgroundColor != null ? Model.Presentation.BackgroundColor.CssClass : "";
}

<section class="section-box @sectionClasses">
    <div class="container">
        @Html.Sitecore().DynamicPlaceholder("pagelayout-pagesection")
    </div>
</section>

We have tried to precompile our cshtml files. This was a major difference and we had the site cold started in under 3 minutes. Unfortunatly, we can only precompile our own code, and we don't have precompiled cshtml and aspx from Sitecore, causing the platform not to work giving the error that those pages are not precompiled. (e.g. login page, experience editor, ...) So precompilation is out of the option.

On IaaS platforms, we do not experience this compilation time of cshtml taking up so much time.

My question: Did anyone experience the same kind of issues? Are there any settings in Azure PaaS that we are missing?

5
  • Since Sitecore 8.2, most of the Speak views are precompiled and bundled in the assemblies (mainly Sitecore.Speak.Components.Web and Sitecore.Speak.Web). Which version of Sitecore are you using?
    – maz
    Sep 26, 2018 at 17:39
  • 9.0-update 1 - you are correct in this, but this is not the standard .net framework compilation. They use razorgenerator to generate class files from their cshtml, which is then compiled. These classes are directly called instead of the cshtml's by tweaking the viewhandler binding. I have been trying to use leverage the same mechanism today, and my first results are possitive. Sep 26, 2018 at 21:06
  • What SKU is your WebApp and what DTU are your databases? Sep 27, 2018 at 0:43
  • What topology are you using? Sep 27, 2018 at 0:48
  • Also see if this applies to you kb.sitecore.net/articles/290593 Sep 27, 2018 at 0:54

2 Answers 2

17

By default Sitecore doesn't use the Roslyn compiler nuget package Microsoft.CodeDom.Providers.DotNetCompilerPlatform, and instead will use the version of Roslyn installed on the system.

I've seen a very noticeably improved compilation performance improvement when using the latest version of that package.

Installation:

  1. Install the latest version of the Microsoft.CodeDom.Providers.DotNetCompilerPlatform nuget package to all projects in the solution.
  2. Make sure your web.config is using the correct CodeDom configuration for the version you have installed. For example:

Web.config

<system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
</system.codedom>
4
  • 1
    This answer works as well. The combination of both solutions (precompile + use dotnetcompilerplatform) can give a good boost to startup performance. Adding DotNetCompilerPlatform made startup approx 50% faster. Jan 18, 2019 at 12:41
  • 1
    Is this applicable for Content Delivery (CD) performance also?
    – Amit Kumar
    Apr 8, 2019 at 17:07
  • @AmitKumar absolutely Apr 10, 2019 at 0:26
  • Thanks for the information. All projects needs to be updated in this case
    – Amit Kumar
    Apr 10, 2019 at 3:30
9

To round up this topic, we ended up using the Razor Generator plugin of visual studio. https://github.com/RazorGenerator/RazorGenerator

And added the assemblies to the precompilation section in sitecore config. (This is the same method sitecore uses to speed up experience editor.)

<?xml version="1.0"?>
<configuration xmlns:x="http://www.sitecore.net/xmlconfig/" xmlns:env="http://www.sitecore.net/xmlconfig/env/">
  <sitecore env:require="!Local">
    <mvc>
      <precompilation>
        <assemblies>
          <assemblyIdentity name="Feature.Jackpot" />
        </assemblies>
      </precompilation>
    </mvc>
  </sitecore>
</configuration>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.