简体   繁体   中英

How to speed up aspnet_compiler.exe?

We have Asp.Net Mvc application for which aspnet_compiler.exe takes more than 5 minutes to run.

The Asp.Net Mvc application is question depends on ~100 smaller projects that all contribute to it different static views, Javascript files, etc... by copying them from their own project folders. These small projects are not web applications in themselves, but they contain web content in order to distribute it between the different projects.

At the end, everything is consolidated under a single web application. And then we run aspnet_compiler.exe, which takes more than 5 minutes. Ouch.

The code targets.Net Framework 4.7.2 and the web applications are not SDK style.

We obviously doing something wrong. How can we reduce this time?

EDIT 1

The whole solution takes ~14.5 minutes to build from scratch using msbuild with /m:12 . The msbuild node utilization is not good. According to the detailed build summary it is:

============================== Node Utilization (IDs represent configurations) ====================================================
Timestamp:            1       2       3       4       5       6       7       8       9       10      11      12       Duration   Cumulative
...
Utilization:          22.8    11.7    17.2    7.2     52.4    16.6    12.8    13.3    13.1    29.8    34.3    14.9     Average Utilization: 20.5104451261997

It is my belief that the poor utilization is due to aspnet_compiler being called relatively late in the build at a point where all the remaining projects depend on the main web application to finish building. I have captured the project build events as chrome traces (inspired by https://github.com/rainersigwald/TraceEventLogger ) here is the bird view picture: 在此处输入图像描述

What looks like a long bridge in the middle is the build event for the main web application. It takes 8:55 minutes to build of which the AspNetCompiler task takes 5:15 minutes.

And so I am trying to understand why it takes so long? I am also exploring other possibilities, like arrange it as a standalone project so that msbuild could queue it on parallel with the projects depending on the main web application. But the main question remains - what can be done about the Asp.Net view precompilation to make it run faster.

Unfortunately, it is a block box for me. I do not really know anything about how it works and what are the ways to optimize it.

aspnet_compiler is slow and does not allow/support parallel compilation internally. It was never updated for performance, or for basic parallel compilation, and is "legacy junk" at this point. It is also not possible to run multiple instances concurrently on the same site. As aspnet_compiler generates many temp files, using a faster drive may help: however, even with a fastest SSD, the CPU is significantly under-utilized.

Using Roslyn can speed up compilation >2x over the .NET Framework provided compiler , although that's the only relevant way I've found to improve performance. It also improves site warmup speed as a result of faster compilation.

Anecdotal performance here,

  • compiles 'hundreds of assemblies' in ~5 minutes
  • compiles website with aspnet_compiler in ~40m ( was ~100m before Roslyn )

I strong recommend using Rosyln , even if this doesn't make the site compilation "fast"; it also allows access to C#7 features from views and ASPX files. Ensure that Rosyln is correctly using the VBCSCompiler.exe service model.

It is more efficient, assuming there are no compilation errors to dig through, to compile an IIS site once instead of once for each application in the site.

Depending on if this is a local build developer build, or for CI/CD, it may also be possible to use a stable output target directory , in which case only modified files should be compiled by default (ie. unless -c is used). YMMV, especially depending on type of changes.

The aspnet_compiler also lacks sufficient output generation to determine which part(s) of a site are taking the most time to compiler. Perhaps this could be added with intercepting the compiler as Roslyn does, or collecting some output therein? Regardless, see initial assertion of "legacy junk".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM