From 1cdc271cd6a3ec00cdd93af0ad9409871c447bb3 Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Fri, 16 Oct 2026 23:51:43 -0700 Subject: [PATCH 1/5] perf(producer): distributed chunks download only the videos they show A project video under compiled/ that chunks extract their own frames from now goes only to the chunks that show it, like video-sources/ files. A chunk skips the readiness wait for a deferred video it does not show, so it no longer logs media_load_failed for a file it was never given. --- .../src/services/distributed/planV2.test.ts | 33 +++++- .../src/services/distributed/planV2.ts | 20 ++-- .../services/distributed/renderChunk.test.ts | 105 +++++++++++++++++- .../src/services/distributed/renderChunk.ts | 23 ++-- 4 files changed, 159 insertions(+), 22 deletions(-) diff --git a/packages/producer/src/services/distributed/planV2.test.ts b/packages/producer/src/services/distributed/planV2.test.ts index 9c1be46b88..87ca9d13b6 100644 --- a/packages/producer/src/services/distributed/planV2.test.ts +++ b/packages/producer/src/services/distributed/planV2.test.ts @@ -450,20 +450,43 @@ describe("Plan v2 manifest", () => { ); }); - it("keeps a deferred source the page itself loads in every chunk", () => { + it("ships each compiled/ video source only to the chunks that show it", () => { const root = tempPath("hf-plan-v2-deferred-compiled-source-"); const v1 = createV1Plan(root, { video: true, videoStart: 1 / 30, deferredSource: "compiled/hero.mp4", }); + // A second clip shown in both chunks, also shipped from compiled/. + const videosPath = join(v1, "meta", "videos.json"); + const videos = JSON.parse(readFileSync(videosPath, "utf-8")) as PlanVideosJson; + const hero = videos.extracted[0]!; + videos.videos.push({ ...videos.videos[0]!, id: "long", src: "long.mp4", start: 0 }); + videos.extracted.push({ + ...hero, + videoId: "long", + deferredRange: { ...hero.deferredRange!, sourcePath: "compiled/long.mp4" }, + }); + writeFileSync(videosPath, JSON.stringify(videos)); + writeFileSync(join(v1, "compiled", "long.mp4"), "long source video"); + refreshV1PlanHash(v1); const manifest = readPlanV2Manifest(createPlanV2FromV1(v1, join(root, "v2")).planDir); + const chunksOf = (path: string) => + manifest.artifacts.find((artifact) => artifact.path === path)?.chunks; expect(manifest.limitations.videoDependencyMode).toBe("source-extract"); - for (const chunkIndex of [0, 1]) { - const artifacts = listPlanV2ArtifactsForTarget(manifest, { role: "chunk", chunkIndex }); - expect(artifacts.some((artifact) => artifact.path === "compiled/hero.mp4")).toBe(true); - } + expect(chunksOf("compiled/hero.mp4")).toEqual([1]); + expect(chunksOf("compiled/long.mp4")).toEqual([0, 1]); + expect(chunksOf("compiled/index.html")).toBe("all"); + expect(chunksOf("compiled/asset.txt")).toBe("all"); + + const chunk0Dir = join(root, "chunk-0"); + materializePlanV2Target(join(root, "v2"), { role: "chunk", chunkIndex: 0 }, chunk0Dir); + expect(existsSync(join(chunk0Dir, "compiled", "hero.mp4"))).toBe(false); + expect(existsSync(join(chunk0Dir, "compiled", "long.mp4"))).toBe(true); + expect(validatePlanV2MaterializedTarget(chunk0Dir, { role: "chunk", chunkIndex: 0 })).not.toBe( + null, + ); }); it("rejects a deferred video source outside the plan directory", () => { diff --git a/packages/producer/src/services/distributed/planV2.ts b/packages/producer/src/services/distributed/planV2.ts index 02183f9bda..690982c758 100644 --- a/packages/producer/src/services/distributed/planV2.ts +++ b/packages/producer/src/services/distributed/planV2.ts @@ -288,8 +288,18 @@ function artifactTargets( if (path === "plan.json" || path === "meta/chunks.json" || path === "meta/encoder.json") { return { chunks: "all", assembler: true }; } - // Each chunk's page loads every