Skip to content

Commit ad508a5

Browse files
committed
perf(ci): overlap two tsgo graphs inside each test-type stripe
Each graph is a serial single-project build, so tsgo gains little past four cores; run 31852071103 measured ~34s/graph on 8 vCPU versus ~42s on hosted 4-core. Overlapping two fresh shard processes per CI stripe (--concurrency 2) uses the idle cores and roughly halves the stripe body; local runs keep the heap-bounded serial default.
1 parent 2702bcf commit ad508a5

2 files changed

Lines changed: 44 additions & 16 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2715,7 +2715,7 @@ jobs:
27152715
echo "[skip] target does not support core test-type stripes"
27162716
exit 0
27172717
fi
2718-
node scripts/run-tsgo-core-test-shards.mjs --stripe "${{ matrix.stripe }}/3"
2718+
node scripts/run-tsgo-core-test-shards.mjs --stripe "${{ matrix.stripe }}/3" --concurrency 2
27192719
27202720
check-additional-shard:
27212721
permissions:

‎scripts/run-tsgo-core-test-shards.mts‎

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Run bounded test graphs in fresh processes so one shard's checker heap cannot
44
// accumulate while the next shard loads. Hold one lock across the full sequence.
5-
import { spawnSync } from "node:child_process";
5+
import { spawn, type ChildProcess } from "node:child_process";
66
import path from "node:path";
77
import {
88
acquireLocalHeavyCheckLockSync,
@@ -35,6 +35,19 @@ if (stripeFlagIndex >= 0) {
3535
process.exit(1);
3636
}
3737
}
38+
// Each graph is a serial single-project build, so tsgo gains little past four
39+
// cores; CI stripe jobs opt into overlapping fresh child processes to use the
40+
// idle cores. Local runs stay serial to keep the heap-bounded default.
41+
const concurrencyFlagIndex = process.argv.indexOf("--concurrency");
42+
let concurrency = 1;
43+
if (concurrencyFlagIndex >= 0) {
44+
const rawConcurrency = process.argv[concurrencyFlagIndex + 1] ?? "";
45+
concurrency = Number(rawConcurrency);
46+
if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 4) {
47+
console.error(`Invalid shard concurrency (expected 1-4): ${rawConcurrency}`);
48+
process.exit(1);
49+
}
50+
}
3851
const env = resolveLocalHeavyCheckEnv(process.env);
3952
const releaseLock =
4053
env.OPENCLAW_TSGO_HEAVY_CHECK_LOCK_HELD === "1"
@@ -45,28 +58,43 @@ const releaseLock =
4558
toolName: "tsgo:core:test",
4659
});
4760

48-
try {
49-
for (const shard of shards) {
50-
const result = spawnSync(
61+
function runShard(config: string): Promise<number> {
62+
return new Promise((resolve, reject) => {
63+
const child: ChildProcess = spawn(
5164
process.execPath,
52-
[path.join(repoRoot, "scripts/run-tsgo.mjs"), "-b", shard.config, "--builders", "1"],
65+
[path.join(repoRoot, "scripts/run-tsgo.mjs"), "-b", config, "--builders", "1"],
5366
{
5467
cwd: repoRoot,
5568
env: { ...env, OPENCLAW_TSGO_HEAVY_CHECK_LOCK_HELD: "1" },
5669
stdio: "inherit",
5770
},
5871
);
59-
if (result.error) {
60-
throw result.error;
61-
}
62-
if (result.signal) {
63-
process.exitCode = signalExitCode(result.signal);
64-
break;
65-
}
66-
if (result.status !== 0) {
67-
process.exitCode = result.status ?? 1;
68-
break;
72+
child.on("error", reject);
73+
child.on("exit", (code, signal) => {
74+
resolve(signal ? signalExitCode(signal) : (code ?? 1));
75+
});
76+
});
77+
}
78+
79+
try {
80+
const queue = [...shards];
81+
let failureCode = 0;
82+
const workers = Array.from({ length: Math.min(concurrency, queue.length) }, async () => {
83+
for (;;) {
84+
const shard = queue.shift();
85+
// Stop draining after the first failure so the exit stays prompt.
86+
if (!shard || failureCode !== 0) {
87+
return;
88+
}
89+
const code = await runShard(shard.config);
90+
if (code !== 0 && failureCode === 0) {
91+
failureCode = code;
92+
}
6993
}
94+
});
95+
await Promise.all(workers);
96+
if (failureCode !== 0) {
97+
process.exitCode = failureCode;
7098
}
7199
} finally {
72100
releaseLock();

0 commit comments

Comments
 (0)