Avoid VBCSCompiler Performance in Roslyn's ASP.NET Razor MVC View?

To support C # 6 in our Razor views on MVC5, we have included the Roslyn compiler platform through web.config:

<system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /> </compilers> </system.codedom> 

However, after production deployments, each view / controller has a noticeable “First boot” delay, which is worse than without turning on this compiler.

It is important to note that this delay is in addition to the regular JIT delay that you receive from the new deployed site. Pages are noticeably slower, and VBCSCompiler.exe runs in the background to "further compile" these pages.

Is there a best practice for pre-compiling / optimizing this situation to avoid delayed mail deployment on first boot? Ideally, VBCSCompiler.exe does not start after deployment and runs at build time.

I saw mentions of aspnet_compiler.exe and ran into StackExchange.Precompilation (see https://blog.stackoverflow.com/2015/07/announcing-stackexchange-precompilation/ ) and wonder if this fix is ​​correct.

Does anyone have any experience with this particular problem? Thanks.

+5
source share
2 answers

You can use RoslynRazorViewEngine from StackExchange.Precompilation :

 ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RoslynRazorViewEngine()); 

the main purpose of this browsing engine, however, is not to get rid of startup performance. With it, you get C # 6 support. Views still need to be compiled at first boot, but roslyn assemblies subsequently fall into the application domain, and you get a higher amount of memory. Since roslyn is called in the application, you do not need special permissions on the web server to execute another .exe from the /bin . We mainly use this for development on our dev machines.

I highly recommend you just precompile all the views . Thus, you do not get the initial performance, and you get the opportunity to check the time of your viewing. You can even run analyzers on the generated view code. That StackOverflow is currently in production.

I mention aspnet_compiler.exe on this blog because it is an original tool for precompiling on ASP.NET (without MVC). Unfortunately, this is very slow.

+1
source

If the Roslyn compiler assemblies are not NGen'd, it may take some time to start VBCScompiler.exe (it refers to several large managed assemblies, and it takes time for their JITs). To shorten the JIT period, you can NGEN build all the Rsolyn assemblies on the machine. You can also find help information from this blog .

0
source

Source: https://habr.com/ru/post/1258017/


All Articles