From 72d50feebce920da4224b254ca66f2102bc18bfb Mon Sep 17 00:00:00 2001 From: JoostK Date: Mon, 14 Sep 2020 14:19:30 +0200 Subject: [PATCH] perf(ngcc): reduce maximum worker count Recent optimizations to ngcc have significantly reduced the total time it takes to process `node_modules`, to such extend that sharding across multiple processes has become less effective. Previously, running ngcc asynchronously would allow for up to 8 workers to be allocated, however these workers have to repeat work that could otherwise be shared. Because ngcc is now able to reuse more shared computations, the overhead of multiple workers is increased and therefore becomes less effective. As an additional benefit, having fewer workers requires less memory and less startup time. To give an idea, using the following test setup: ```bash npx @angular/cli new perf-test cd perf-test yarn ng add @angular/material ./node_modules/.bin/ngcc --properties es2015 module main \ --first-only --create-ivy-entry-points ``` We observe the following figures on CI: | | 10.1.1 | PR #38840 | | ----------------- | --------- | --------- | | Sync | 85s | 25s | | Async (8 workers) | 22s | 16s | | Async (4 workers) | - | 11s | --- packages/compiler-cli/ngcc/src/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/ngcc/src/main.ts b/packages/compiler-cli/ngcc/src/main.ts index d87bd556cd096..efaa5e7912e94 100644 --- a/packages/compiler-cli/ngcc/src/main.ts +++ b/packages/compiler-cli/ngcc/src/main.ts @@ -162,8 +162,8 @@ function getExecutor( const {retryAttempts, retryDelay} = config.getLockingConfig(); const locker = new AsyncLocker(lockFile, logger, retryDelay, retryAttempts); if (inParallel) { - // Execute in parallel. Use up to 8 CPU cores for workers, always reserving one for master. - const workerCount = Math.min(8, os.cpus().length - 1); + // Execute in parallel. Use up to 4 CPU cores for workers, always reserving one for master. + const workerCount = Math.min(4, os.cpus().length - 1); return new ClusterExecutor( workerCount, fileSystem, logger, fileWriter, pkgJsonUpdater, locker, createTaskCompletedCallback);