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
25 changes: 22 additions & 3 deletions scripts/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,27 @@ function selectTargets() {
const origLog = console.log;
console.log = (...args) => console.error(...args);

// ───── Issue #1054 timing instrumentation (one-off) ─────
// Per-iteration phase breakdown so we can see which step eats the 2s/call
// CI overhead. Throwaway after we read the gate logs.
function logTrace(scenario: string, iter: number, totalMs: number, phases: any) {
const p = phases || {};
const order = [
'setupMs', 'collectMs', 'detectMs', 'parseMs', 'insertMs', 'resolveMs',
'edgesMs', 'structureMs', 'rolesMs', 'astMs', 'complexityMs', 'cfgMs',
'dataflowMs', 'finalizeMs',
];
const parts = order.map(k => `${k.replace(/Ms$/, '')}=${p[k] ?? '?'}`).join(' ');
console.error(`[1054-trace] ${engine}.${scenario}[${iter}] total=${Math.round(totalMs)}ms ${parts}`);
}

// Clean DB for a full build
if (fs.existsSync(dbPath)) fs.unlinkSync(dbPath);

const buildStart = performance.now();
const buildResult = await buildGraph(root, { engine, incremental: false });
const buildTimeMs = performance.now() - buildStart;
logTrace('full', 0, buildTimeMs, buildResult?.phases);

const queryStart = performance.now();
fnDepsData('buildGraph', dbPath);
Expand All @@ -150,8 +165,10 @@ try {
const noopTimings = [];
for (let i = 0; i < INCREMENTAL_RUNS; i++) {
const start = performance.now();
await buildGraph(root, { engine, incremental: true });
noopTimings.push(performance.now() - start);
const res = await buildGraph(root, { engine, incremental: true });
const elapsed = performance.now() - start;
noopTimings.push(elapsed);
logTrace('noop', i, elapsed, res?.phases);
}
noopRebuildMs = Math.round(median(noopTimings));
} catch (err) {
Expand All @@ -168,7 +185,9 @@ try {
fs.writeFileSync(PROBE_FILE, original + `\n// probe-${i}\n`);
const start = performance.now();
const res = await buildGraph(root, { engine, incremental: true });
oneFileRuns.push({ ms: performance.now() - start, phases: res?.phases || null });
const elapsed = performance.now() - start;
oneFileRuns.push({ ms: elapsed, phases: res?.phases || null });
logTrace('1file', i, elapsed, res?.phases);
}
oneFileRuns.sort((a, b) => a.ms - b.ms);
const medianRun = oneFileRuns[Math.floor(oneFileRuns.length / 2)];
Expand Down
32 changes: 27 additions & 5 deletions scripts/incremental-benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,31 @@ function median(arr) {

console.error(`Benchmarking ${engine} engine...`);

// ───── Issue #1054 timing instrumentation (one-off) ─────
// Emits per-iteration phase breakdown for every buildGraph call so we can
// see which step eats the 2s/call CI overhead that doesn't reproduce locally.
// The plan: dispatch the gate against this branch, read the log, then
// throw the branch away.
function logTrace(scenario: string, iter: number, totalMs: number, phases: any) {
const p = phases || {};
const order = [
'setupMs', 'collectMs', 'detectMs', 'parseMs', 'insertMs', 'resolveMs',
'edgesMs', 'structureMs', 'rolesMs', 'astMs', 'complexityMs', 'cfgMs',
'dataflowMs', 'finalizeMs',
];
const parts = order.map(k => `${k.replace(/Ms$/, '')}=${p[k] ?? '?'}`).join(' ');
console.error(`[1054-trace] ${engine}.${scenario}[${iter}] total=${Math.round(totalMs)}ms ${parts}`);
}

// Full build (delete DB first)
const fullTimings = [];
for (let i = 0; i < RUNS; i++) {
if (fs.existsSync(dbPath)) fs.unlinkSync(dbPath);
const start = performance.now();
await buildGraph(root, { engine, incremental: false });
fullTimings.push(performance.now() - start);
const res = await buildGraph(root, { engine, incremental: false });
const elapsed = performance.now() - start;
fullTimings.push(elapsed);
logTrace('full', i, elapsed, res?.phases);
}
const fullBuildMs = Math.round(median(fullTimings));

Expand All @@ -182,8 +200,10 @@ try {
const noopTimings = [];
for (let i = 0; i < RUNS; i++) {
const start = performance.now();
await buildGraph(root, { engine, incremental: true });
noopTimings.push(performance.now() - start);
const res = await buildGraph(root, { engine, incremental: true });
const elapsed = performance.now() - start;
noopTimings.push(elapsed);
logTrace('noop', i, elapsed, res?.phases);
}
noopRebuildMs = Math.round(median(noopTimings));
} catch (err) {
Expand All @@ -200,7 +220,9 @@ try {
fs.writeFileSync(PROBE_FILE, original + `\n// probe-${i}\n`);
const start = performance.now();
const res = await buildGraph(root, { engine, incremental: true });
oneFileRuns.push({ ms: performance.now() - start, phases: res?.phases || null });
const elapsed = performance.now() - start;
oneFileRuns.push({ ms: elapsed, phases: res?.phases || null });
logTrace('1file', i, elapsed, res?.phases);
}
oneFileRuns.sort((a, b) => a.ms - b.ms);
const medianRun = oneFileRuns[Math.floor(oneFileRuns.length / 2)];
Expand Down
Loading