Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ jobs:
{"os":"ubuntu-latest","node-version":24,"shard":1,"shardTotal":3},
{"os":"ubuntu-latest","node-version":24,"shard":2,"shardTotal":3},
{"os":"ubuntu-latest","node-version":24,"shard":3,"shardTotal":3},
{"os":"windows-latest","node-version":22,"shard":1,"shardTotal":3},
{"os":"windows-latest","node-version":22,"shard":2,"shardTotal":3},
{"os":"windows-latest","node-version":22,"shard":3,"shardTotal":3}]}'
{"os":"windows-latest","node-version":22,"shard":1,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":2,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":3,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":4,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":5,"shardTotal":5}]}'
CORE_STATIC='{"include":[{"os":"ubuntu-latest","node-version":24},{"os":"windows-latest","node-version":22}]}'
FULL_TEST='{"include":[
{"os":"ubuntu-latest","node-version":22,"shard":1,"shardTotal":3},
Expand All @@ -137,12 +139,16 @@ jobs:
{"os":"ubuntu-latest","node-version":24,"shard":1,"shardTotal":3},
{"os":"ubuntu-latest","node-version":24,"shard":2,"shardTotal":3},
{"os":"ubuntu-latest","node-version":24,"shard":3,"shardTotal":3},
{"os":"windows-latest","node-version":22,"shard":1,"shardTotal":3},
{"os":"windows-latest","node-version":22,"shard":2,"shardTotal":3},
{"os":"windows-latest","node-version":22,"shard":3,"shardTotal":3},
{"os":"windows-latest","node-version":24,"shard":1,"shardTotal":3},
{"os":"windows-latest","node-version":24,"shard":2,"shardTotal":3},
{"os":"windows-latest","node-version":24,"shard":3,"shardTotal":3}]}'
{"os":"windows-latest","node-version":22,"shard":1,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":2,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":3,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":4,"shardTotal":5},
{"os":"windows-latest","node-version":22,"shard":5,"shardTotal":5},
{"os":"windows-latest","node-version":24,"shard":1,"shardTotal":5},
{"os":"windows-latest","node-version":24,"shard":2,"shardTotal":5},
{"os":"windows-latest","node-version":24,"shard":3,"shardTotal":5},
{"os":"windows-latest","node-version":24,"shard":4,"shardTotal":5},
{"os":"windows-latest","node-version":24,"shard":5,"shardTotal":5}]}'
FULL_STATIC='{"include":[
{"os":"ubuntu-latest","node-version":22},
{"os":"ubuntu-latest","node-version":24},
Expand Down
8 changes: 8 additions & 0 deletions scripts/ci-shard-partition.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface ShardWeights {
msPerLineFallback: number;
files: Record<string, number>;
}

export function lineCount(rel: string): number;
export function fileWeight(rel: string, table?: ShardWeights): number;
export function partitionAll(files: string[], n: number, table?: ShardWeights): string[][];
58 changes: 58 additions & 0 deletions scripts/ci-shard-partition.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Shard partitioning with MEASURED-duration weights (#4360).
//
// Line-count LPT balanced bytes, not seconds: process-spawning suites
// (node child per case) cost orders of magnitude more per line than pure
// assertion files, and the line-count layout piled several of them into one
// shard (5-way split ran 5min..37min legs from a "perfectly balanced" 48.9K
// lines/shard). Weight = last measured wall-clock ms per file
// (scripts/ci-shard-weights.json, regenerated by
// scripts/measure-test-durations.mjs); files missing from the table fall
// back to lineCount * msPerLineFallback so a NEW file still gets a sane
// first-run weight. The partition stays DETERMINISTIC and TOTAL: fixed
// weights => same bins every run, and every file lands in exactly one bin.
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));

let defaultTable = { msPerLineFallback: 15, files: {} };
try {
const raw = JSON.parse(readFileSync(join(ROOT, "scripts", "ci-shard-weights.json"), "utf8"));
if (typeof raw?.msPerLineFallback === "number" && raw?.files && typeof raw.files === "object") {
defaultTable = raw;
}
} catch {
// absent/malformed table => pure line-count fallback (old behavior)
}

export function lineCount(rel) {
try {
return Math.max(1, readFileSync(join(ROOT, rel), "utf8").split("\n").length);
} catch {
return 1;
}
}

export function fileWeight(rel, table = defaultTable) {
const measured = table.files[rel];
if (typeof measured === "number" && measured > 0) return measured;
return Math.round(lineCount(rel) * (table.msPerLineFallback || 15));
}

// LPT bin-packing over fileWeight: sort desc (ties by path asc), assign each
// file to the currently-lightest bin (lowest index breaks ties). Targets the
// HEAVIEST shard (the wall clock), not equal file counts.
export function partitionAll(files, n, table = defaultTable) {
const weight = (f) => fileWeight(f, table);
const order = [...files].sort((a, b) => weight(b) - weight(a) || (a < b ? -1 : a > b ? 1 : 0));
const bins = Array.from({ length: n }, () => []);
const load = new Array(n).fill(0);
for (const f of order) {
let best = 0;
for (let k = 1; k < n; k++) if (load[k] < load[best]) best = k;
bins[best].push(f);
load[best] += weight(f);
}
return bins;
}
Loading
Loading