简体   繁体   English

为什么aspnet_compiler.exe这么慢(可以更快)?

[英]Why is aspnet_compiler.exe so slow (and can it be made any faster)?

During our build process we run aspnet_compiler.exe against our websites to make sure that all the late-bound stuff in ASP.NET/MVC actually builds (I know nothing about ASP.NET but am assured this is necessary to prevent finding the failures at runtime). 在我们的构建过程中,我们对我们的网站运行aspnet_compiler.exe ,以确保ASP.NET / MVC中所有后期绑定的内容实际构建(我对ASP.NET一无所知但我确信这是必要的,以防止在运行)。

Our sites are fairly large in size, with a few hundred pages/views/controls/etc. 我们的网站规模相当大,有几百页/视图/控件/等。 however the time taken seems excessive in the 10-15 minute range (for reference, this is longer than it takes the entire solution with approx 40 projects to compile, and we're only pre-compiling two website projects). 然而,在10-15分钟范围内所花费的时间似乎过多(作为参考,这比整个解决方案需要大约40个项目的编译时间更长,我们只是预编译了两个网站项目)。

I doubt that hardware is the issue as I'm running on the latest Quad core Intel chip, with 4GB RAM and a WD Velociraptor 10,000rpm hard disk. 我怀疑硬件是问题,因为我运行的是最新的四核英特尔芯片,配备4GB内存和WD Velociraptor 10,000rpm硬盘。 And part of what's odd is that the EXE doesn't seem to be using much CPU (1-5%) and doesn't seem to be doing an awful lot of I/O either. 而奇怪的部分是EXE似乎没有使用太多的CPU(1-5%)并且似乎也没有做太多的I / O.

So... is this a known issue? 那么......这是一个众所周知的问题吗? Why is it so slow? 为什么这么慢? And is there any way to speed it up? 有没有办法加快速度?

Note: To clarify a couple of things people have answered about, I am not talking about the compilation of code within Visual Studio. 注意:为了澄清人们已经回答的一些事情,我不是在谈论Visual Studio中的代码编译。 We're using web application projects already, and the speed of compilation of those is not the issue. 我们已经在使用Web应用程序项目了,编译速度不是问题。 The problem is the pre-compilation of the site after these projects have already been compiled ( see this MSDN page for more details ) as part of the dev build script. 问题是在已经编译这些项目之后预先编译网站( 有关详细信息,请参阅此MSDN页面 )作为开发构建脚本的一部分。 We are performing in-place pre-compilation, not copying the files to a target directory. 我们正在执行就地预编译,而不是将文件复制到目标目录。

Switching to Roslyn compiler most likely will significantly improve precompile time. 切换到Roslyn编译器最有可能显着改善预编译时间。 Here is a good article about it: http://blogs.msdn.com/b/webdev/archive/2014/05/12/enabling-the-net-compiler-platform-roslyn-in-asp-net-applications.aspx . 这是一篇很好的文章: http//blogs.msdn.com/b/webdev/archive/2014/05/12/enabling-the-net-compiler-platform-roslyn-in-asp-net-applications。 aspx

In addition to this, make sure that batch compilation is enabled by setting batch attribute to true on the compilation element. 除此之外,还要确保通过在编译元素上将批处理属性设置为true来启用批处理编译。

Simply, the aspnet_compiler uses what is effectively a "global compiler lock" whenever it starts pre-compiling any individual aspx page; 简单地说,每当aspnet_compiler开始预编译任何单独的aspx页面时, aspnet_compiler使用“全局编译器锁”。 it is basically only allowed to compile each page sequentially. 它基本上只允许按顺序编译每个页面。

There are reasons for this (although I personally disagree with them) - primarily, in order to detect and prevent circular references causing an infinite loop of sorts, as well as ensuring that all dependencies are properly built before the requiring page is compiled, they avoid a lot of "nasty CS issues". 这是有原因的(虽然我个人不同意) - 主要是为了检测和防止导致无限循环排序的循环引用,以及确保在编译需求页​​面之前正确构建所有依赖项,它们避免很多“令人讨厌的CS问题”。

I once started writing a massively-forked version of aspnet_compiler.exe last time I worked at a web company, but got tied up with "real work" and never finished it. 上次我在一家网络公司工作时,我曾经开始编写一个大量分叉的aspnet_compiler.exe版本,但却被“真正的工作”所束缚,从未完成它。 Biggest problem is the ASPX pages: the MVC/Razor stuff you can parallelize the HELL out of, but the ASPX parse/compile engine is about 20 levels deep of internal and private classes/methods. 最大的问题是ASPX页面:你可以将HELL并行化的MVC / Razor,但ASPX解析/编译引擎大约是内部和私有类/方法的20级。

  1. Compiler should generate second code-behind file for every .aspx page, check 编译器应为每个.aspx页面生成第二个代码隐藏文件, 请检查
  2. During compilation, aspnet_compiler.exe will copy ALL of the web site files to the output directory, including css, js and images. 在编译期间,aspnet_compiler.exe会将所有网站文件复制到输出目录,包括css,js和images。

You'll get better compilation times using Web application project instead of Web site model. 使用Web应用程序项目而不是Web站点模型,您将获得更好的编译时间。

我没有针对这个编译器的任何特定热门技巧,但是当我遇到这种问题时,我运行ProcMon来查看该进程在机器上正在做什么,并且我运行Wireshark来检查它是否花费了很多时间 - 对某个注册表项或环境变量中引用的长时间遗忘的计算机的某些网络访问。

Just my 2 cents. 只需2美分。

One of the things slowing down ASP.NET views precompilation significantly is the -fixednames command line option for aspnet_compiler.exe . 减慢ASP.NET视图预编译的一个-fixednamesaspnet_compiler.exe-fixednames命令行选项。 Do not use it especially if you're on Razor/MVC. 如果您使用的是Razor / MVC,请不要使用它

When publishing the wep app from Visual Studio make sure you select "Do not merge", and do not select "create separate assembly" cause this is what causes the global lock and slows things down. 从Visual Studio发布wep应用程序时,请确保选择“不合并”,并且不要选择“创建单独的程序集”,因为这是导致全局锁定并减慢速度的原因。

在此输入图像描述

More info here https://msdn.microsoft.com/en-us/library/hh475319(v=vs.110).aspx 更多信息请访问https://msdn.microsoft.com/en-us/library/hh475319(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 aspnet_compiler.exe是否特殊? - Is aspnet_compiler.exe special? 如何加速aspnet_compiler.exe? - How to speed up aspnet_compiler.exe? aspnet_compiler.exe在全局别名中找到多种类型,但是我不能! - aspnet_compiler.exe finding multiple types in global alias, but I can't! 您能指定aspnet_compiler.exe是否创建调试版本或发布版本? - Can you specify if aspnet_compiler.exe creates a debug or release build? 不使用aspnet_compiler.exe的-u选项时的副作用 - Side effects when not using the -u option of aspnet_compiler.exe 使用aspnet_compiler.exe编译.Net Web Apps - Using the aspnet_compiler.exe to compile .Net Web Apps 包括ASP文件时,“ aspnet_compiler.exe”退出并显示代码1”错误 - “aspnet_compiler.exe” exited with code 1" error when including ASP file “ aspnet_compiler.exe”以代码1退出,尝试了所有其他具有相同标题的帖子 - “aspnet_compiler.exe” exited with code 1, tried all the other posts with the same title 什么是使用aspnet_compiler.exe预编译ASP.NET项目的优势? - Whats the advantage of pre-compiling ASP.NET project using aspnet_compiler.exe? 您对如何加快预编译Kentico网站有任何建议吗? 又名:aspnet_compiler非常慢 - Do you have any suggestions on how to speed up precompiling a Kentico site? AKA: the aspnet_compiler is VERY slow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM