diff --git a/src/BuildPrediction/ProjectGraphPredictionExecutor.cs b/src/BuildPrediction/ProjectGraphPredictionExecutor.cs index bb827e1..755f6db 100644 --- a/src/BuildPrediction/ProjectGraphPredictionExecutor.cs +++ b/src/BuildPrediction/ProjectGraphPredictionExecutor.cs @@ -80,15 +80,16 @@ public void PredictInputsAndOutputs( { foreach (var projectNode in projectGraph.ProjectNodes) { - ExecuteAllPredictors(projectNode, _projectPredictors, _projectGraphPredictors, projectPredictionCollector); + ExecuteAllPredictors(projectNode, _projectPredictors, _projectGraphPredictors, projectPredictionCollector, _options.MaxDegreeOfParallelismPerProject); } } else { + int maxDegreeOfParallelismPerProject = _options.MaxDegreeOfParallelismPerProject; Parallel.ForEach( projectGraph.ProjectNodes.ToArray(), new ParallelOptions() { MaxDegreeOfParallelism = _options.MaxDegreeOfParallelism }, - projectNode => ExecuteAllPredictors(projectNode, _projectPredictors, _projectGraphPredictors, projectPredictionCollector)); + projectNode => ExecuteAllPredictors(projectNode, _projectPredictors, _projectGraphPredictors, projectPredictionCollector, maxDegreeOfParallelismPerProject)); } } @@ -96,12 +97,13 @@ private static void ExecuteAllPredictors( ProjectGraphNode projectGraphNode, ValueAndTypeName[] projectPredictors, ValueAndTypeName[] projectGraphPredictors, - IProjectPredictionCollector projectPredictionCollector) + IProjectPredictionCollector projectPredictionCollector, + int maxDegreeOfParallelismPerProject) { ProjectInstance projectInstance = projectGraphNode.ProjectInstance; - // Run the project predictors. Use single-threaded prediction since we're already parallelizing on projects. - ProjectPredictionExecutor.ExecuteProjectPredictors(projectInstance, projectPredictors, projectPredictionCollector, maxDegreeOfParallelism: 1); + // Run the project predictors. + ProjectPredictionExecutor.ExecuteProjectPredictors(projectInstance, projectPredictors, projectPredictionCollector, maxDegreeOfParallelismPerProject); // Run the graph predictors for (var i = 0; i < projectGraphPredictors.Length; i++) diff --git a/src/BuildPrediction/ProjectPredictionOptions.cs b/src/BuildPrediction/ProjectPredictionOptions.cs index 3a51333..59ad656 100644 --- a/src/BuildPrediction/ProjectPredictionOptions.cs +++ b/src/BuildPrediction/ProjectPredictionOptions.cs @@ -17,5 +17,22 @@ public sealed class ProjectPredictionOptions /// If the caller of is parallelizing across projects, it's recommended to set this to 1 to avoid over-scheduling. /// public int MaxDegreeOfParallelism { get; set; } = Environment.ProcessorCount; + + /// + /// Gets or sets the max degree of parallelism to use for running predictors within a single project during graph prediction. + /// Defaults to 1, meaning predictors for each project run sequentially. + /// + /// + /// + /// When using , projects are processed in parallel (controlled by ), + /// and predictors within each project are processed with this level of parallelism. The total thread usage may be up to + /// × , so care should be taken to avoid over-subscription. + /// + /// + /// Increasing this value can help when individual projects are bottlenecks (e.g. projects with many items that take a long time to predict), + /// but it assumes all predictors are thread-safe. Built-in predictors are thread-safe, but custom predictors should be verified. + /// + /// + public int MaxDegreeOfParallelismPerProject { get; set; } = 1; } } \ No newline at end of file