Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(ngcc): only create tasks for non-processed formats (#35719) #35832

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/compiler-cli/ngcc/src/execution/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface Task extends JsonObject {

/**
* The list of all format properties (including `task.formatProperty`) that should be marked as
* processed once the taksk has been completed, because they point to the format-path that will be
* processed once the task has been completed, because they point to the format-path that will be
* processed as part of the task.
*/
formatPropertiesToMarkAsProcessed: EntryPointJsonProperty[];
Expand All @@ -75,9 +75,6 @@ export type TaskCompletedCallback = (task: Task, outcome: TaskProcessingOutcome)

/** Represents the outcome of processing a `Task`. */
export const enum TaskProcessingOutcome {
/** The target format property was already processed - didn't have to do anything. */
AlreadyProcessed,

/** Successfully processed the target format property. */
Processed,
}
Expand Down
23 changes: 15 additions & 8 deletions packages/compiler-cli/ngcc/src/execution/cluster/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class ClusterMaster {
}

run(): Promise<void> {
if (this.taskQueue.allTasksCompleted) {
return Promise.resolve();
}

// Set up listeners for worker events (emitted on `cluster`).
cluster.on('online', this.wrapEventHandler(worker => this.onWorkerOnline(worker.id)));

Expand All @@ -51,10 +55,8 @@ export class ClusterMaster {
'exit',
this.wrapEventHandler((worker, code, signal) => this.onWorkerExit(worker, code, signal)));

// Start the workers.
for (let i = 0; i < this.workerCount; i++) {
cluster.fork();
}
// Since we have pending tasks at the very minimum we need a single worker.
cluster.fork();

return this.finishedDeferred.promise.then(() => this.stopWorkers(), err => {
this.stopWorkers();
Expand Down Expand Up @@ -98,11 +100,16 @@ export class ClusterMaster {
isWorkerAvailable = false;
}

// If there are no available workers or no available tasks, log (for debugging purposes).
if (!isWorkerAvailable) {
this.logger.debug(
`All ${this.taskAssignments.size} workers are currently busy and cannot take on more ` +
'work.');
if (this.taskAssignments.size < this.workerCount) {
this.logger.debug('Spawning another worker process as there is more work to be done.');
cluster.fork();
} else {
// If there are no available workers or no available tasks, log (for debugging purposes).
this.logger.debug(
`All ${this.taskAssignments.size} workers are currently busy and cannot take on more ` +
'work.');
}
} else {
const busyWorkers = Array.from(this.taskAssignments)
.filter(([_workerId, task]) => task !== null)
Expand Down
15 changes: 7 additions & 8 deletions packages/compiler-cli/ngcc/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {ParallelTaskQueue} from './execution/task_selection/parallel_task_queue'
import {SerialTaskQueue} from './execution/task_selection/serial_task_queue';
import {ConsoleLogger, LogLevel} from './logging/console_logger';
import {Logger} from './logging/logger';
import {hasBeenProcessed, markAsProcessed} from './packages/build_marker';
import {hasBeenProcessed} from './packages/build_marker';
import {NgccConfiguration} from './packages/configuration';
import {EntryPoint, EntryPointJsonProperty, EntryPointPackageJson, SUPPORTED_FORMAT_PROPERTIES, getEntryPointFormat} from './packages/entry_point';
import {makeEntryPointBundle} from './packages/entry_point_bundle';
Expand Down Expand Up @@ -207,6 +207,12 @@ export function mainNgcc(
}

for (const formatProperty of propertiesToProcess) {
if (hasBeenProcessed(entryPoint.packageJson, formatProperty)) {
// The format-path which the property maps to is already processed - nothing to do.
logger.debug(`Skipping ${entryPoint.name} : ${formatProperty} (already compiled).`);
continue;
}

const formatPropertiesToMarkAsProcessed = equivalentPropertiesMap.get(formatProperty) !;
tasks.push({entryPoint, formatProperty, formatPropertiesToMarkAsProcessed, processDts});

Expand Down Expand Up @@ -256,13 +262,6 @@ export function mainNgcc(
`${formatProperty} (formatPath: ${formatPath} | format: ${format})`);
}

// The format-path which the property maps to is already processed - nothing to do.
if (hasBeenProcessed(packageJson, formatProperty)) {
logger.debug(`Skipping ${entryPoint.name} : ${formatProperty} (already compiled).`);
onTaskCompleted(task, TaskProcessingOutcome.AlreadyProcessed);
return;
}

const bundle = makeEntryPointBundle(
fileSystem, entryPoint, formatPath, isCore, format, processDts, pathMappings, true,
enableI18nLegacyMessageIdFormat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,8 @@ describe('ClusterWorker', () => {
new ClusterWorker(mockLogger, createCompileFnSpy);
const onTaskCompleted: TaskCompletedCallback = createCompileFnSpy.calls.argsFor(0)[0];

onTaskCompleted(null as any, TaskProcessingOutcome.AlreadyProcessed);
expect(processSendSpy).toHaveBeenCalledTimes(1);
expect(processSendSpy).toHaveBeenCalledWith({
type: 'task-completed',
outcome: TaskProcessingOutcome.AlreadyProcessed,
});

onTaskCompleted(null as any, TaskProcessingOutcome.Processed);
expect(processSendSpy).toHaveBeenCalledTimes(2);
expect(processSendSpy).toHaveBeenCalledTimes(1);
expect(processSendSpy).toHaveBeenCalledWith({
type: 'task-completed',
outcome: TaskProcessingOutcome.Processed,
Expand Down