避免在Roslyn支持的ASP.NET Razor MVC视图上击中VBCSCompiler性能? [英] Avoid VBCSCompiler perf hit on Roslyn powered ASP.NET Razor MVC views?

查看:41
本文介绍了避免在Roslyn支持的ASP.NET Razor MVC视图上击中VBCSCompiler性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在MVC5的Razor视图中支持C#6,我们通过web.config打开了Roslyn编译器平台:

In order to support C# 6 in our Razor views on MVC5, we turned on the Roslyn compiler platform via 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 appears to have a noticeable "First Load" delay that is worse than without this compiler being enabled.

重要的是,此延迟是从正在部署的新站点获得的常规JIT延迟之外的.页面明显较慢,而VBCSCompiler.exe似乎在后台运行以进一步编译"这些页面.

Importantly, this delay is in addition to the regular JIT delay you get from a new site being deployed. Pages are noticably slower, while it appears VBCSCompiler.exe runs in the background to "further compile" these pages.

是否存在用于预编译/优化此情况的最佳实践,以消除部署后的首次加载运行时延迟?理想情况下,部署完成后VBCSCompiler.exe不会运行,而是在构建时执行.

Is there a best practice for pre-compiling/optimizing this situation to eliminate the first-load runtime delay post deployment? Ideally VBCSCompiler.exe is not running after a deployment occurs, and is performed at build-time.

我已经看到过提及aspnet_compiler.exe的情况,并且遇到了StackExchange.Precompilation(请参见 https://blog.stackoverflow.com/2015/07/announcing-stackexchange-precompilation/),想知道这是否是正确的解决方法.

I've seen mentions of aspnet_compiler.exe and have come across StackExchange.Precompilation (see https://blog.stackoverflow.com/2015/07/announcing-stackexchange-precompilation/) and wonder if this is the right fix.

有人对这个特殊问题有经验吗?谢谢.

Does anyone have any experience with this particular problem? Thank you.

推荐答案

您可以使用此视图引擎的主要目标,但是不是要摆脱启动性能方面的问题.有了它,您将获得C#6支持.视图仍然必须在第一次加载时进行编译,但是roslyn程序集随后会在应用程序域中终止,并且您会获得更大的内存占用量.由于roslyn在应用程序中被调用,因此您不需要Web服务器上的特殊权限即可执行/bin 文件夹中的另一个 .exe .我们主要将其用于开发机器上的开发.

The main goal of this view engine, however, is not to get rid of the startup perf hit. With it you just get C#6 support. The views still have to be compiled on first load, but the roslyn assemblies end up in the app domain afterwards, and you get a higher memory footprint. Since roslyn is called in the app, you don't need special permissions on the web server for executing another .exe from the /bin folder. We mostly use this for development on our dev machines.

我强烈建议您预编译所有视图.这样,您就不会遇到启动性能方面的问题,并且可以对视图进行编译时验证.您甚至可以在生成的视图代码上运行分析器.这就是StackOverflow当前在生产环境中运行的方式.

I strongly recommend you just precompile all the views. This way you get no startup perf hit, and you gain compile time verification of your views. You could even run analyzers on the generated view code. That's what StackOverflow currently runs in production.

我在该博客文章中提到了 aspnet_compiler.exe ,因为它是在ASP.NET(无MVC)上进行预编译的原始工具.不幸的是,它非常慢.

I mention aspnet_compiler.exe in that blog post, because it's the original tool for precompilation on ASP.NET (sans MVC). Unfortunatelly it's very slow.

这篇关于避免在Roslyn支持的ASP.NET Razor MVC视图上击中VBCSCompiler性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆