Skip to content

Commit

Permalink
[One .NET] run per-RID builds in parallel (dotnet#6338)
Browse files Browse the repository at this point in the history
Context: https://docs.microsoft.com/visualstudio/msbuild/msbuild-task

During .NET 6 builds, we run a portion of the build in an
`<MSBuild/>` task nested build per-`$(RuntimeIdentifier)`.

The work in the nested build is done in separate directories for each
RID, so we should be able to do the work in parallel for:

  * `ILLink`
  * AOT compilation

We have to use the `%(AdditionalProperties)` item metadata on the
list of projects (which is the same project) passed to the
`<MSBuild/>` task.

One point of concern is when you have a property at the end of
`%(AdditionalProperties)`:

	_OuterIntermediateOutputPath=$(IntermediateOutputPath);

The `;` will be included in the path if this is the last property!

I reworked `$(_AdditionalProperties)` so that there will not be any
trailing `;` that could cause issues.

~~ Results ~~

Building `dotnet new android` on my Windows PC with `--no-restore`.
This is currently two RIDs by default.
Δ = Improvement = (1-(After/Before))*100%.

|                   |    Before (s) |     After (s) |   Δ |
| ----------------: | ------------: | ------------: | --: |
|             Debug |   00:00:06.86 |   00:00:06.76 |  1% |
|           Release |   00:00:19.00 |   00:00:13.53 | 29% |
|  Release with AOT |   00:00:23.95 |   00:00:17.72 | 26% |

A `Debug` build has small improvement.  `Release` builds have the
most improvement, saving 5-6 seconds.

Apps with four RIDs could have even more savings.
  • Loading branch information
jonathanpeppers authored Sep 27, 2021
1 parent 033b658 commit 33a6d1e
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,25 @@ _ResolveAssemblies MSBuild target.
<_RIDs Include="$(RuntimeIdentifiers)" Condition=" '$(RuntimeIdentifiers)' != '' " />
</ItemGroup>
<PropertyGroup>
<_ProguardProjectConfiguration Condition=" '$(AndroidLinkTool)' != '' ">$(IntermediateOutputPath)proguard\proguard_project_references.cfg</_ProguardProjectConfiguration>
<_ProguardProjectConfiguration Condition=" '$(AndroidLinkTool)' != '' ">;_ProguardProjectConfiguration=$(IntermediateOutputPath)proguard\proguard_project_references.cfg</_ProguardProjectConfiguration>
<_AdditionalProperties>
_ComputeFilesToPublishForRuntimeIdentifiers=true;
AppendRuntimeIdentifierToOutputPath=true;
SkipCompilerExecution=true;
_OuterIntermediateAssembly=@(IntermediateAssembly);
_OuterOutputPath=$(OutputPath);
_OuterIntermediateOutputPath=$(IntermediateOutputPath);
_ProguardProjectConfiguration=$(_ProguardProjectConfiguration);
_ComputeFilesToPublishForRuntimeIdentifiers=true
;AppendRuntimeIdentifierToOutputPath=true
;SkipCompilerExecution=true
;_OuterIntermediateAssembly=@(IntermediateAssembly)
;_OuterOutputPath=$(OutputPath)
;_OuterIntermediateOutputPath=$(IntermediateOutputPath)
$(_ProguardProjectConfiguration)
</_AdditionalProperties>
<_AndroidBuildRuntimeIdentifiersInParallel Condition=" '$(_AndroidBuildRuntimeIdentifiersInParallel)' == '' ">true</_AndroidBuildRuntimeIdentifiersInParallel>
</PropertyGroup>
<ItemGroup>
<_ProjectToBuild Include="$(MSBuildProjectFile)" AdditionalProperties="RuntimeIdentifier=%(_RIDs.Identity);$(_AdditionalProperties)" />
</ItemGroup>
<MSBuild
Projects="$(MSBuildProjectFile)"
Targets="_ComputeFilesToPublishForRuntimeIdentifiers"
Properties="RuntimeIdentifier=%(_RIDs.Identity);$(_AdditionalProperties)">
Projects="@(_ProjectToBuild)"
BuildInParallel="$(_AndroidBuildRuntimeIdentifiersInParallel)"
Targets="_ComputeFilesToPublishForRuntimeIdentifiers">
<Output TaskParameter="TargetOutputs" ItemName="ResolvedFileToPublish" />
</MSBuild>
<ItemGroup>
Expand Down

0 comments on commit 33a6d1e

Please sign in to comment.