Skip to content

Commit dab6639

Browse files
committed
test(cli): time check per phase on windows and linux runners
1 parent e44f456 commit dab6639

7 files changed

Lines changed: 182 additions & 24 deletions

File tree

‎.github/checkfast/prof-table.mjs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// usage: node prof-table.mjs <outdir> -> per fixture median ms per profile row
2+
import { readdirSync, readFileSync } from "node:fs";
3+
const dir = process.argv[2];
4+
const byFx = {};
5+
for (const f of readdirSync(dir).filter((f) => f.endsWith(".err"))) {
6+
const fx = f.replace(/-\d+\.err$/, "");
7+
const line = readFileSync(`${dir}/${f}`, "utf8").split("\n").find((l) => l.startsWith("__HF_PROFILE__"));
8+
if (!line) continue;
9+
const p = JSON.parse(line.slice("__HF_PROFILE__".length));
10+
(byFx[fx] ??= []).push(p);
11+
}
12+
const med = (a) => { const s = [...a].sort((x, y) => x - y); return s[Math.floor(s.length / 2)]; };
13+
for (const [fx, runs] of Object.entries(byFx)) {
14+
console.log(`\n## ${fx} (${runs.length} runs) node wall median ${med(runs.map((r) => r.wallMs))} ms`);
15+
const names = [...new Set(runs.flatMap((r) => r.rows.map((x) => x.name)))];
16+
const rows = names.map((n) => {
17+
const ms = runs.map((r) => r.rows.find((x) => x.name === n)?.ms ?? 0);
18+
const cnt = runs[0].rows.find((x) => x.name === n)?.n ?? 0;
19+
return { n, ms: med(ms), cnt };
20+
}).sort((a, b) => b.ms - a.ms);
21+
for (const r of rows) console.log(`${String(r.ms).padStart(7)} x${String(r.cnt).padEnd(4)} ${r.n}`);
22+
}

‎.github/checkfast/run.sh‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Times `hyperframes check` per phase on 6 fixtures (3 runs each), plus node boot and process spawn floors.
2+
set -u
3+
CLI="node packages/cli/dist/cli.js"
4+
OUT=checkfast-out; mkdir -p $OUT/runs $OUT/cpuprof
5+
ms() { s=$(date +%s%N); "$@" >/dev/null 2>&1; e=$(date +%s%N); echo $(( (e-s)/1000000 )); }
6+
$CLI browser ensure > $OUT/browser.log 2>&1 || $CLI browser > $OUT/browser.log 2>&1
7+
for i in $(seq 10); do
8+
echo "bare $(ms node -e 0) version $(ms $CLI --version) git $(ms git --version) ffprobe $(ms ffprobe -version)"
9+
done | tee $OUT/floors.txt
10+
FX="registry/examples/kinetic-type registry/examples/decision-tree registry/examples/product-promo packages/producer/tests/fast-capture-gsap/src packages/producer/tests/chat/src packages/producer/tests/heygen-promo-preview-assets/src"
11+
W=$RUNNER_TEMP/cf-fx; mkdir -p $W
12+
cp -r packages/producer/tests/chat/src $W/warmup; $CLI check $W/warmup --json > /dev/null 2>&1
13+
for round in 1 2 3; do
14+
for src in $FX; do
15+
fx=$(basename $src); [ $fx = src ] && fx=$(basename $(dirname $src))
16+
D=$W/$fx-$round; cp -r $src $D
17+
s=$(date +%s%N)
18+
HF_CHECK_PROFILE=1 $CLI check $D --json > $OUT/runs/$fx-$round.json 2> $OUT/runs/$fx-$round.err
19+
code=$?; e=$(date +%s%N)
20+
echo "$fx run$round exit=$code wall_ms=$(( (e-s)/1000000 ))" | tee -a $OUT/summary.txt
21+
done
22+
done
23+
cp -r packages/producer/tests/chat/src $W/cpuprof
24+
node --cpu-prof --cpu-prof-dir=$OUT/cpuprof packages/cli/dist/cli.js check $W/cpuprof --json > /dev/null 2>&1
25+
node .github/checkfast/prof-table.mjs $OUT/runs | tee $OUT/prof-table.txt
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: checkfast timing
2+
on:
3+
push:
4+
branches: [checkfast/windows-timing]
5+
permissions:
6+
contents: read
7+
jobs:
8+
time:
9+
name: check timing ${{ matrix.os }} defender-${{ matrix.defender }}
10+
runs-on: ${{ matrix.os }}
11+
timeout-minutes: 40
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- { os: windows-latest, defender: on }
17+
- { os: windows-latest, defender: off }
18+
- { os: ubuntu-latest, defender: none }
19+
env:
20+
HYPERFRAMES_NO_TELEMETRY: "1"
21+
DO_NOT_TRACK: "1"
22+
HYPERFRAMES_SKIP_SKILLS: "1"
23+
steps:
24+
- name: Disable Windows Defender real-time monitoring
25+
if: matrix.defender == 'off'
26+
shell: pwsh
27+
run: Set-MpPreference -DisableRealtimeMonitoring $true
28+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
29+
with:
30+
lfs: true
31+
- name: Install FFmpeg (Windows)
32+
if: runner.os == 'Windows'
33+
uses: ./.github/actions/install-ffmpeg-windows
34+
- name: Install FFmpeg (Linux)
35+
if: runner.os == 'Linux'
36+
run: sudo apt-get update -qq && sudo apt-get install -y -qq ffmpeg
37+
- name: Set FFMPEG_BIN for bun install
38+
if: runner.os == 'Windows'
39+
shell: pwsh
40+
run: |
41+
$path = (Get-Command ffmpeg.exe).Source
42+
"FFMPEG_BIN=$path" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
43+
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
44+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
45+
with:
46+
node-version: 24
47+
- name: Defender state
48+
if: runner.os == 'Windows'
49+
shell: pwsh
50+
run: Get-MpComputerStatus | Select-Object RealTimeProtectionEnabled, AntivirusEnabled | Format-List
51+
- run: bun install --frozen-lockfile
52+
- run: bun run build
53+
- name: Time check
54+
shell: bash
55+
run: bash .github/checkfast/run.sh
56+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
57+
if: always()
58+
with:
59+
name: checkfast-${{ matrix.os }}-${{ matrix.defender }}
60+
path: checkfast-out

‎packages/cli/src/capture/captureCompositionFrame.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from "../browser/launch.js";
66
import { oneProcessOverPipe } from "../browser/sandboxDenied.js";
77
import { spawn } from "node:child_process";
8+
import { prof } from "../utils/_prof.js";
89
import type { Browser, Page } from "puppeteer-core";
910
import type { InProcessRequest, InProcessResponse } from "../utils/staticProjectServer.js";
1011
import { c } from "../ui/colors.js";
@@ -233,7 +234,7 @@ async function waitForCompositionSettle(
233234
page: Page,
234235
options: OpenSettledCompositionPageOptions,
235236
): Promise<boolean> {
236-
const runtimeReady = await waitForRuntimeReady(page, options.renderReadyTimeoutMs);
237+
const runtimeReady = await prof("o.runtimeReady", () => waitForRuntimeReady(page, options.renderReadyTimeoutMs));
237238

238239
if (!runtimeReady) {
239240
console.warn(
@@ -249,7 +250,7 @@ async function waitForCompositionSettle(
249250
console.warn(` ${c.warn("⚠")} Shader transitions did not finish pre-rendering`);
250251
});
251252

252-
await waitForLateSubresources(page);
253+
await prof("o.lateSubresources", () => waitForLateSubresources(page));
253254
return runtimeReady;
254255
}
255256

@@ -310,18 +311,18 @@ export async function openSettledCompositionPage(
310311
let chromeBrowser: Browser | undefined;
311312
try {
312313
const launched =
313-
(await options.prelaunched?.take(launchKey(html, noListen, options))) ??
314+
(await prof("o.take", async () => options.prelaunched?.take(launchKey(html, noListen, options)))) ??
314315
(await launchCompositionBrowser(html, noListen, options));
315316
chromeBrowser = launched.browser;
316317
const softwareWebGpu = launched.softwareWebGpu;
317318
options.onBrowser?.(chromeBrowser);
318319
options.onBrowserReady?.();
319-
const page = await chromeBrowser.newPage();
320+
const page = await prof("o.newPage", () => chromeBrowser!.newPage());
320321
await installPageFunctionGuard(page);
321322
await page.setViewport(viewport);
322323
if (answer) await answerPageInProcess(page, url, answer);
323324
await options.beforeNavigate?.(page);
324-
await gotoWhenSent(page, url, pageNavigationTimeoutMs(options.navigationTimeoutMs));
325+
await prof("o.goto", () => gotoWhenSent(page, url, pageNavigationTimeoutMs(options.navigationTimeoutMs)));
325326
await assertWebGpuAdapterAvailable(page, requiresWebGpu, softwareWebGpu);
326327
const renderReadyTimedOut = !(await waitForCompositionSettle(page, options));
327328
return { browser: chromeBrowser, page, renderReadyTimedOut };
@@ -337,7 +338,7 @@ async function launchCompositionBrowser(
337338
): Promise<LaunchedBrowser> {
338339
const viewport = resolveCompositionViewportFromHtml(html);
339340
const { ensureBrowser, findSystemBrowser } = await import("../browser/manager.js");
340-
const browser = await ensureBrowser({ signal: options.signal });
341+
const browser = await prof("o.ensureBrowser", () => ensureBrowser({ signal: options.signal }));
341342
const puppeteer = await import("puppeteer-core");
342343
const { buildChromeArgs } = await import("@hyperframes/engine");
343344
const requestedGpuMode = options.browserGpuMode ?? resolveCliChromeGpuMode();
@@ -367,7 +368,7 @@ async function launchCompositionBrowser(
367368

368369
let chromeBrowser: Browser;
369370
try {
370-
chromeBrowser = await launch(browser.executablePath);
371+
chromeBrowser = await prof("o.launch", () => launch(browser.executablePath));
371372
} catch (launchError) {
372373
const message = normalizeErrorMessage(launchError);
373374
const remediation = windowsChromeCrashRemediation(message);

‎packages/cli/src/utils/_prof.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// TEMP profiler (checkfast measurement only, never committed).
2+
const totals = new Map<string, { ms: number; n: number }>();
3+
const on = process.env.HF_CHECK_PROFILE === "1";
4+
const t0 = Date.now();
5+
let firstSpanAt = -1;
6+
7+
function add(name: string, ms: number): void {
8+
const entry = totals.get(name) ?? { ms: 0, n: 0 };
9+
entry.ms += ms;
10+
entry.n += 1;
11+
totals.set(name, entry);
12+
}
13+
14+
export async function prof<T>(name: string, fn: () => Promise<T> | T): Promise<T> {
15+
if (!on) return fn();
16+
const start = performance.now();
17+
if (firstSpanAt < 0) firstSpanAt = Math.round(start);
18+
try {
19+
return await fn();
20+
} finally {
21+
add(name, performance.now() - start);
22+
}
23+
}
24+
25+
export function profSpan(name: string): () => void {
26+
const start = performance.now();
27+
return () => {
28+
if (on) add(name, performance.now() - start);
29+
};
30+
}
31+
32+
export function profObject<T extends object>(prefix: string, target: T): T {
33+
if (!on) return target;
34+
for (const key of Object.keys(target) as (keyof T)[]) {
35+
const fn = target[key];
36+
if (typeof fn !== "function") continue;
37+
target[key] = ((...args: unknown[]) =>
38+
prof(`${prefix}.${String(key)}`, () => (fn as (...a: unknown[]) => unknown)(...args))) as T[keyof T];
39+
}
40+
return target;
41+
}
42+
43+
if (on) {
44+
process.on("exit", () => {
45+
const rows = [...totals.entries()].map(([name, v]) => ({ name, ms: Math.round(v.ms), n: v.n }));
46+
process.stderr.write(`\n__HF_PROFILE__${JSON.stringify({ wallMs: Date.now() - t0, firstSpanAt, exitAt: Math.round(performance.now()), rows })}\n`);
47+
});
48+
}

‎packages/cli/src/utils/checkBrowser.ts‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { CheckDeadline } from "./checkDeadline.js";
2+
import { prof, profObject } from "./_prof.js";
23
import { BrowserCleanupError, closeManagedBrowser } from "../browser/launch.js";
34
import { checkSnapshotDirectory } from "./checkSnapshotDirectory.js";
45
import { mkdirSync, writeFileSync } from "node:fs";
@@ -210,7 +211,7 @@ export async function runBrowserCheck(
210211
prelaunched?: PrelaunchedBrowser,
211212
): Promise<CheckBrowserResult> {
212213
const { bundleWithLocalizedFonts } = await import("./bundleWithLocalizedFonts.js");
213-
const html = await bundleWithLocalizedFonts(project.dir);
214+
const html = await prof("b.bundle", () => bundleWithLocalizedFonts(project.dir));
214215
const { findings: drafts, failedPaths } = await preResolveHostileMediaProxies(
215216
project.dir,
216217
html,
@@ -254,26 +255,26 @@ export async function runBrowserCheck(
254255
});
255256
chromeBrowser = session.browser;
256257
const page = session.page;
257-
await waitForPreferredSeekTarget(page);
258+
await prof("b.preferredTarget", () => waitForPreferredSeekTarget(page));
258259

259-
const rootAnchor = await resolveRootAnchor(page);
260+
const rootAnchor = await prof("b.rootAnchor", () => resolveRootAnchor(page));
260261
const launchSettleMs = Date.now() - launchSettleStart;
261262
// validate's per-media-element audit, kept in the consolidation: a clip
262263
// whose intrinsic duration is meaningfully shorter than its data-duration
263264
// slot silently shortens the slot at render time — invisible to lint (no
264265
// intrinsic durations statically) and to the runtime listeners (nothing
265266
// errors). The session is already open, so this is one extra evaluate.
266267
const { analyzeClipMediaFit } = await import("@hyperframes/engine");
267-
for (const entry of await auditClipDurations(page, analyzeClipMediaFit, options.timeout)) {
268+
for (const entry of await prof("b.clipMediaFit", () => auditClipDurations(page, analyzeClipMediaFit, options.timeout))) {
268269
drafts.push({ code: "clip_media_fit", severity: entry.level, message: entry.text, time: 0 });
269270
}
270-
for (const tail of findTweenTails((await page.evaluate(collectTweenRecords)) ?? [])) {
271+
for (const tail of findTweenTails((await prof("b.tweenRecords", () => page.evaluate(collectTweenRecords))) ?? [])) {
271272
const message = tweenTailMessage(tail);
272273
drafts.push({ code: "gsap_tween_tail", severity: "warning", message, time: tail.later.end });
273274
}
274-
const driver = createPageDriver(page, clock);
275-
const result = await runGrid(driver, options, motion);
276-
const broken = await abortedImagesStillBroken(page, drafts);
275+
const driver = profObject("d", createPageDriver(page, clock));
276+
const result = await prof("b.grid", () => runGrid(driver, options, motion));
277+
const broken = await prof("b.abortedImages", () => abortedImagesStillBroken(page, drafts));
277278
return {
278279
...result,
279280
timings: { ...result.timings, launchSettleMs },
@@ -286,7 +287,7 @@ export async function runBrowserCheck(
286287
failure = { kind: "failed", error };
287288
throw error;
288289
} finally {
289-
await closeCheckResources(chromeBrowser, server, failure);
290+
await prof("b.close", () => closeCheckResources(chromeBrowser, server, failure));
290291
}
291292
}
292293

‎packages/cli/src/utils/checkPipeline.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { BrowserCleanupError } from "../browser/launch.js";
2+
import { prof } from "./_prof.js";
23
import { CheckDeadline, CheckDeadlineError } from "./checkDeadline.js";
34
import {
45
checkSnapshotDirectory,
@@ -476,7 +477,7 @@ async function collectGridSamples(
476477
if (contrastSet.has(time))
477478
await collectContrastAt(driver, options, time, issuesAtTime, collected);
478479
}
479-
await collectMotionOverlapSamples(driver, grid, collected, options.range);
480+
await prof("g.denseOverlap", () => collectMotionOverlapSamples(driver, grid, collected, options.range));
480481
return collected;
481482
}
482483

@@ -1234,7 +1235,7 @@ export async function runAuditGrid(
12341235
grid.duration,
12351236
);
12361237
const seekLoopStart = Date.now();
1237-
const collected = await collectGridSamples(driver, options, grid, plan);
1238+
const collected = await prof("g.loop", () => collectGridSamples(driver, options, grid, plan));
12381239
const seekLoopMs = Date.now() - seekLoopStart;
12391240

12401241
let motionIssues = plan.preflightIssues;
@@ -1312,7 +1313,7 @@ export async function runCheckPipeline(
13121313
let lintResult: ProjectLintResult;
13131314
const lintStartedAt = Date.now();
13141315
try {
1315-
lintResult = await dependencies.lintProject(project.dir);
1316+
lintResult = await prof("p.lint", () => dependencies.lintProject(project.dir));
13161317
} catch (error) {
13171318
// The linter itself crashed (unreadable file, internal error) — distinct
13181319
// from lint findings; a runtime-failure code would send the agent hunting
@@ -1329,9 +1330,9 @@ export async function runCheckPipeline(
13291330
let hdrPromotion: CheckReport["hdr"]["autoPromotion"] = null;
13301331
let hdrInspection: CheckReport["hdr"]["inspection"] = "available";
13311332
try {
1332-
hdrPromotion = await (dependencies.inspectHdrAutoPromotion ?? inspectHdrAutoPromotion)(
1333+
hdrPromotion = await prof("p.hdr", () => (dependencies.inspectHdrAutoPromotion ?? inspectHdrAutoPromotion)(
13331334
project,
1334-
);
1335+
));
13351336
} catch {
13361337
hdrInspection = "unavailable";
13371338
}
@@ -1367,9 +1368,9 @@ export async function runCheckPipeline(
13671368
let browser: CheckBrowserResult;
13681369
try {
13691370
const browserAhead = await prelaunched;
1370-
browser = await deadline.run(() =>
1371+
browser = await prof("p.browser", () => deadline.run(() =>
13711372
dependencies.runBrowserCheck(project, options, motion, deadline, browserAhead),
1372-
);
1373+
));
13731374
} catch (error) {
13741375
browser = emptyBrowserResult();
13751376
browser.runtimeFindings.push(runtimeFailure(error));
@@ -1398,7 +1399,7 @@ export async function runCheckPipeline(
13981399
outcome = { kind: "failed", error };
13991400
}
14001401
try {
1401-
await deadline.close();
1402+
await prof("p.deadlineClose", () => deadline.close());
14021403
} catch (error) {
14031404
if (outcome.kind === "failed") {
14041405
throw new BrowserCleanupError(

0 commit comments

Comments
 (0)