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

fix(core): calculate project dependencies upfront in the schedule #28152

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/nx/src/tasks-runner/tasks-schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class TasksSchedule {
private completedTasks = new Set<string>();
private scheduleRequestsExecutionChain = Promise.resolve();
private estimatedTaskTimings: Record<string, number> = {};
private projectDependencies: Record<string, number> = {};

constructor(
private readonly projectGraph: ProjectGraph,
Expand All @@ -42,6 +43,15 @@ export class TasksSchedule {
Object.values(this.taskGraph.tasks).map((t) => t.target)
);
}

for (const project of Object.values(this.taskGraph.tasks).map(
(t) => t.target.project
)) {
this.projectDependencies[project] ??= findAllProjectNodeDependencies(
project,
this.reverseProjectGraph
).length;
}
}

public async scheduleNextTasks() {
Expand Down Expand Up @@ -125,14 +135,8 @@ export class TasksSchedule {
const project1 = this.taskGraph.tasks[taskId1].target.project;
const project2 = this.taskGraph.tasks[taskId2].target.project;

const project1NodeDependencies = findAllProjectNodeDependencies(
project1,
this.reverseProjectGraph
).length;
const project2NodeDependencies = findAllProjectNodeDependencies(
project2,
this.reverseProjectGraph
).length;
const project1NodeDependencies = this.projectDependencies[project1];
const project2NodeDependencies = this.projectDependencies[project2];

const dependenciesDiff =
project2NodeDependencies - project1NodeDependencies;
Expand Down