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
This commit is contained in:
Miguel Ángel
2026-11-04 21:04:35 +00:00
committed by GitHub
parent 00ea86570a
commit be8122d0c4
2 changed files with 34 additions and 1 deletions
+18
View File
@@ -2943,6 +2943,24 @@ describe("check pipeline", () => {
expect(sampled.some((time) => Math.round(time * 1000) % 125 !== 0)).toBe(true);
});
it("thins the craft grid when frames are slow, so the pass stays near its budget and still reaches the end", async () => {
let clock = 0;
vi.spyOn(performance, "now").mockImplementation(() => clock);
const driver = craftDriver({
getDuration: vi.fn(async () => 60),
collectCraftFrame: vi.fn(async (time: number) => {
clock += 1000;
return craftFrame(time);
}),
});
const { report } = await runScenario(driver);
expect(report.craft.samples).toBeGreaterThan(20);
expect(report.craft.samples).toBeLessThan(120);
expect(report.craft.step).toBeGreaterThan(0.5);
expect(report.craft.step).toBeLessThanOrEqual(1.5);
});
it("samples a long film at 8 fps, finer than the overlap pass's capped grid", async () => {
// A 60 s film whose seven-word line shows 10.1-10.3 s, between two of the overlap grid's samples.
const driver = craftDriver({
+16 -1
View File
@@ -758,12 +758,18 @@ async function collectMotionOverlapSamples(
const craftStart = performance.now();
// The render's last frame lands before the duration, where the runtime has already unmounted clips.
const craftTimes = buildCraftSampleTimes(grid.duration).filter((time) => time < grid.duration);
for (const [index, time] of craftTimes.entries()) {
const last = craftTimes.length - 1;
for (let index = 0, sampled = 1; index <= last; sampled += 1) {
const time = craftTimes[index]!;
progress(`craft frame at ${time}s`);
await driver.seekGeometry(time, { draws: true });
collected.craftFrames.push(...(await collectCraftFrame(driver, time)));
progress();
report("craft", index + 1, craftTimes.length);
index =
index === last
? last + 1
: Math.min(last, index + craftStride(craftStart, sampled, last - index));
}
collected.craftMs = Math.round(performance.now() - craftStart);
}
@@ -785,6 +791,15 @@ async function collectMotionOverlapSamples(
// Craft times how long a line shows, so it keeps 8 fps past the overlap pass's ceiling, up to ~75 s.
const CRAFT_SAMPLE_FPS = 8;
const CRAFT_MAX_SAMPLES = 600;
const CRAFT_BUDGET_MS = 90_000;
const CRAFT_MAX_STRIDE = 12;
function craftStride(startedAt: number, sampled: number, remaining: number): number {
const spent = performance.now() - startedAt;
const left = CRAFT_BUDGET_MS - spent;
const wanted = left <= 0 ? remaining : Math.ceil(((spent / sampled) * remaining) / left);
return Math.min(CRAFT_MAX_STRIDE, Math.max(1, wanted));
}
function buildCraftSampleTimes(duration: number): number[] {
if (!Number.isFinite(duration) || duration <= 0) return [];