forked from xamarin/xamarin-macios
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[msbuild] Make the level of parallelism configurable in all tasks tha…
…t call Parallel.ForEach. Fixes xamarin#20210. This deduplicates some code, and also ensures we specifiy a max limit to the level of parallelism. This fixes an issue in the AOTCompile and ScnTool tasks, where we'd have no limit, launching as many subprocesses as tasks there are to execute. In particular for the AOTCompile task, this can put a rather heavy burden on build machines, slowing everything down to a crawl. Fixes xamarin#20210.
- Loading branch information
1 parent
8cfbe6f
commit 318b285
Showing
7 changed files
with
44 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
using Xamarin.Localization.MSBuild; | ||
using Xamarin.Utils; | ||
|
||
#nullable enable | ||
|
||
namespace Xamarin.MacDev.Tasks { | ||
public abstract class XamarinParallelTask : XamarinTask { | ||
// How many tasks we execute in parallel. Default is number of processors / 2. | ||
public string MaxDegreeOfParallelism { get; set; } = string.Empty; | ||
|
||
int GetMaxDegreeOfParallelism () | ||
{ | ||
if (!string.IsNullOrEmpty (MaxDegreeOfParallelism)) { | ||
if (int.TryParse (MaxDegreeOfParallelism, out var max)) | ||
return max; | ||
Log.LogWarning (MSBStrings.W7121 /* Unable to parse the value '{0}' for the property 'MaxDegreeOfParallelism'. Falling back to the default value (number of processors / 2). */, MaxDegreeOfParallelism); | ||
} | ||
return Math.Max (Environment.ProcessorCount / 2, 1); | ||
} | ||
|
||
protected void ForEach<TSource> (IEnumerable<TSource> source, Action<TSource> body) | ||
{ | ||
var options = new ParallelOptions { MaxDegreeOfParallelism = GetMaxDegreeOfParallelism () }; | ||
Parallel.ForEach (source, options, body); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters