From 4c63241b343a4b01cdb54408b69802ee1d045eba Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Wed, 29 Apr 2020 21:28:03 +0300 Subject: [PATCH] fix(ngcc): do not run in parallel mode if there are less than 3 CPU cores (#36626) Previously, ngcc would run in parallel mode (using the `ClusterExecutor`) when there were at least 2 CPU cores (and all other requirements where met). On systems with just 2 CPU cores, this meant there would only be one worker process (since one CPU core is always reserved for the master process). In these cases, the tasks would still be processed serially (on the one worker process), but we would also pay the overhead of communicating between the master and worker processes. This commit fixes this by only running in parallel mode if there are more than 2 CPU cores (i.e. at least 2 worker processes). PR Close #36626 --- packages/compiler-cli/ngcc/src/main.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/ngcc/src/main.ts b/packages/compiler-cli/ngcc/src/main.ts index 02ddbf7ab2..f3c5359a74 100644 --- a/packages/compiler-cli/ngcc/src/main.ts +++ b/packages/compiler-cli/ngcc/src/main.ts @@ -86,8 +86,10 @@ export function mainNgcc(options: NgccOptions): void|Promise { return; } - // Execute in parallel, if async execution is acceptable and there are more than 1 CPU cores. - const inParallel = async && (os.cpus().length > 1); + // Execute in parallel, if async execution is acceptable and there are more than 2 CPU cores. + // (One CPU core is always reserved for the master process and we need at least 2 worker processes + // in order to run tasks in parallel.) + const inParallel = async && (os.cpus().length > 2); const analyzeEntryPoints = getAnalyzeEntryPointsFn( logger, finder, fileSystem, supportedPropertiesToConsider, compileAllFormats,