Skip to content

Commit 5f4436d

Browse files
authored
Keep a small reserve of tasks to not-batch, so all threads can have always have an initial task (#18696)
* Keep a small reserve of tasks to not-batch, so all threads can have an initial task" * Assign no weight to new tests, but still place them at the end of the list
1 parent 38905f4 commit 5f4436d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/harness/parallel/host.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ namespace Harness.Parallel.Host {
4444
console.log("Discovering tests...");
4545
const discoverStart = +(new Date());
4646
const { statSync }: { statSync(path: string): { size: number }; } = require("fs");
47-
const tasks: { runner: TestRunnerKind, file: string, size: number }[] = [];
47+
let tasks: { runner: TestRunnerKind, file: string, size: number }[] = [];
48+
const newTasks: { runner: TestRunnerKind, file: string, size: number }[] = [];
4849
const perfData = readSavedPerfData();
4950
let totalCost = 0;
5051
let unknownValue: string | undefined;
@@ -60,15 +61,18 @@ namespace Harness.Parallel.Host {
6061
const hashedName = hashName(runner.kind(), file);
6162
size = perfData[hashedName];
6263
if (size === undefined) {
63-
size = Number.MAX_SAFE_INTEGER;
64+
size = 0;
6465
unknownValue = hashedName;
66+
newTasks.push({ runner: runner.kind(), file, size });
67+
continue;
6568
}
6669
}
6770
tasks.push({ runner: runner.kind(), file, size });
6871
totalCost += size;
6972
}
7073
}
7174
tasks.sort((a, b) => a.size - b.size);
75+
tasks = tasks.concat(newTasks);
7276
// 1 fewer batches than threads to account for unittests running on the final thread
7377
const batchCount = runners.length === 1 ? workerCount : workerCount - 1;
7478
const packfraction = 0.9;
@@ -174,7 +178,7 @@ namespace Harness.Parallel.Host {
174178
let scheduledTotal = 0;
175179
batcher: while (true) {
176180
for (let i = 0; i < batchCount; i++) {
177-
if (tasks.length === 0) {
181+
if (tasks.length <= workerCount) { // Keep a small reserve even in the suboptimally packed case
178182
console.log(`Suboptimal packing detected: no tests remain to be stolen. Reduce packing fraction from ${packfraction} to fix.`);
179183
break batcher;
180184
}
@@ -213,7 +217,9 @@ namespace Harness.Parallel.Host {
213217
worker.send({ type: "batch", payload });
214218
}
215219
else { // Unittest thread - send off just one test
216-
worker.send({ type: "test", payload: tasks.pop() });
220+
const payload = tasks.pop();
221+
ts.Debug.assert(!!payload); // The reserve kept above should ensure there is always an initial task available, even in suboptimal scenarios
222+
worker.send({ type: "test", payload });
217223
}
218224
}
219225
}

0 commit comments

Comments
 (0)