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
This commit is contained in:
George Kalpakas 2020-04-29 21:28:03 +03:00 committed by Andrew Kushnir
parent 9aa778e843
commit 4c63241b34
1 changed files with 4 additions and 2 deletions

View File

@ -86,8 +86,10 @@ export function mainNgcc(options: NgccOptions): void|Promise<void> {
return; return;
} }
// Execute in parallel, if async execution is acceptable and there are more than 1 CPU cores. // Execute in parallel, if async execution is acceptable and there are more than 2 CPU cores.
const inParallel = async && (os.cpus().length > 1); // (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( const analyzeEntryPoints = getAnalyzeEntryPointsFn(
logger, finder, fileSystem, supportedPropertiesToConsider, compileAllFormats, logger, finder, fileSystem, supportedPropertiesToConsider, compileAllFormats,