Skip to content

Commit be8122d

Browse files
fix(cli): check thins its craft samples when frames are slow, so the pass ends near 90 seconds (#7183)
* fix(cli): check thins its craft samples when frames are slow, so the pass ends near 90 seconds * style(cli): format the craft loop * fix(cli): cap the craft stride so the widened grid stays under the dead-stretch threshold
1 parent 00ea865 commit be8122d

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎packages/cli/src/commands/check.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2943,6 +2943,24 @@ describe("check pipeline", () => {
29432943
expect(sampled.some((time) => Math.round(time * 1000) % 125 !== 0)).toBe(true);
29442944
});
29452945

2946+
it("thins the craft grid when frames are slow, so the pass stays near its budget and still reaches the end", async () => {
2947+
let clock = 0;
2948+
vi.spyOn(performance, "now").mockImplementation(() => clock);
2949+
const driver = craftDriver({
2950+
getDuration: vi.fn(async () => 60),
2951+
collectCraftFrame: vi.fn(async (time: number) => {
2952+
clock += 1000;
2953+
return craftFrame(time);
2954+
}),
2955+
});
2956+
const { report } = await runScenario(driver);
2957+
2958+
expect(report.craft.samples).toBeGreaterThan(20);
2959+
expect(report.craft.samples).toBeLessThan(120);
2960+
expect(report.craft.step).toBeGreaterThan(0.5);
2961+
expect(report.craft.step).toBeLessThanOrEqual(1.5);
2962+
});
2963+
29462964
it("samples a long film at 8 fps, finer than the overlap pass's capped grid", async () => {
29472965
// A 60 s film whose seven-word line shows 10.1-10.3 s, between two of the overlap grid's samples.
29482966
const driver = craftDriver({

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,12 +758,18 @@ async function collectMotionOverlapSamples(
758758
const craftStart = performance.now();
759759
// The render's last frame lands before the duration, where the runtime has already unmounted clips.
760760
const craftTimes = buildCraftSampleTimes(grid.duration).filter((time) => time < grid.duration);
761-
for (const [index, time] of craftTimes.entries()) {
761+
const last = craftTimes.length - 1;
762+
for (let index = 0, sampled = 1; index <= last; sampled += 1) {
763+
const time = craftTimes[index]!;
762764
progress(`craft frame at ${time}s`);
763765
await driver.seekGeometry(time, { draws: true });
764766
collected.craftFrames.push(...(await collectCraftFrame(driver, time)));
765767
progress();
766768
report("craft", index + 1, craftTimes.length);
769+
index =
770+
index === last
771+
? last + 1
772+
: Math.min(last, index + craftStride(craftStart, sampled, last - index));
767773
}
768774
collected.craftMs = Math.round(performance.now() - craftStart);
769775
}
@@ -785,6 +791,15 @@ async function collectMotionOverlapSamples(
785791
// Craft times how long a line shows, so it keeps 8 fps past the overlap pass's ceiling, up to ~75 s.
786792
const CRAFT_SAMPLE_FPS = 8;
787793
const CRAFT_MAX_SAMPLES = 600;
794+
const CRAFT_BUDGET_MS = 90_000;
795+
const CRAFT_MAX_STRIDE = 12;
796+
797+
function craftStride(startedAt: number, sampled: number, remaining: number): number {
798+
const spent = performance.now() - startedAt;
799+
const left = CRAFT_BUDGET_MS - spent;
800+
const wanted = left <= 0 ? remaining : Math.ceil(((spent / sampled) * remaining) / left);
801+
return Math.min(CRAFT_MAX_STRIDE, Math.max(1, wanted));
802+
}
788803

789804
function buildCraftSampleTimes(duration: number): number[] {
790805
if (!Number.isFinite(duration) || duration <= 0) return [];

0 commit comments

Comments
 (0)