commit df4a4f6912fc6b806abab1bc82b7dc85e9d9b136
parent 0041242cf6f057bc309342b73dd24a4eb8abcb96
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 27 Oct 2026 02:32:53 -0400
chrome frame reuse: a run of frames follows the run it came from
One key is often drawn by many frames (a still stretch), and the
renderer's workers draw the same still a hair apart (measured: the same
page with 6 and 7 workers differs in 249 of 10,458 feed frames, a few
pixels by a few levels). Taking one old frame for every frame of its key
changed the bytes of frames that had not changed, and so the key of every
encode chunk over them: the Huck intro proof re-encoded 32 chunks for
'feed frames changed' with 225 frames captured. Now each frame takes the
old frame after the one its predecessor took when that is of its key,
else the nearest of its key to that place.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 55 insertions(+), 5 deletions(-)
diff --git a/umtool/report-to-video/compose-chrome.mjs b/umtool/report-to-video/compose-chrome.mjs
@@ -1209,15 +1209,25 @@ export function frameListHtml(html, region, runs, fps) {
async function reuseFrames({ base, target, stem, fk, key, html, region, rate, hf, workers, quality, assetsDir }) {
const chrome = path.join(base, "chrome");
const candidates = [target, path.join(chrome, `work-from-${stem}-frames`), path.join(chrome, `work-from-own-${stem}-frames`)];
+ // Every frame on disk, by key: `occ` holds each key's frames as ids
+ // (source × 1e7 + frame index), ascending.
+ const dirs = [];
+ const keysOf = [];
+ const occ = new Map();
const have = new Map();
- let sources = 0;
for (const dir of candidates) {
const keys = await readFile(path.join(dir, FRAME_KEYS_FILE), "utf8").then((t) => t.split("\n").filter(Boolean), () => null);
if (!keys || (await framesOnDisk(dir)) !== keys.length) continue;
- sources += 1;
- keys.forEach((k, i) => { if (!have.has(k)) have.set(k, path.join(dir, frameName(i + 1))); });
+ const d = dirs.length;
+ dirs.push(dir);
+ keysOf.push(keys);
+ keys.forEach((k, i) => {
+ if (!occ.has(k)) occ.set(k, []);
+ occ.get(k).push(d * 1e7 + i);
+ if (!have.has(k)) have.set(k, true);
+ });
}
- if (!sources) return null;
+ if (!dirs.length) return null;
const missing = [];
for (let i = 0; i < fk.length; i += 1) if (!have.has(fk[i])) missing.push(i);
if (missing.length > fk.length * 0.9) return null;
@@ -1245,10 +1255,43 @@ async function reuseFrames({ base, target, stem, fk, key, html, region, rate, hf
capture.forEach((i, j) => have.set(fk[i], path.join(capDir, frameName(j + 1))));
}
+ // Which frame on disk each frame is. One key is often drawn by many frames
+ // (a still stretch), and the renderer's workers draw it a hair differently
+ // (measured: a few pixels, a few levels), so taking any one of them for all
+ // would change the bytes of frames that did not change -- and every chunk
+ // of the final encode over them. So a run of frames follows the run it
+ // came from: the frame after the one the last frame took, when it is of
+ // the same key; else the frame of this key nearest that place.
+ // (`off`: where the last frame taken sat against this one, kept across a
+ // captured frame, so a run resumes where it left off.)
+ const pick = new Array(fk.length);
+ let off = 0;
+ for (let i = 0; i < fk.length; i += 1) {
+ const list = occ.get(fk[i]);
+ let g = -1;
+ if (list) {
+ const want = i + off;
+ const d = Math.floor(want / 1e7), n = want % 1e7;
+ if (want >= 0 && keysOf[d]?.[n] === fk[i]) g = want;
+ else {
+ let lo = 0, hi = list.length - 1;
+ while (lo < hi) {
+ const mid = (lo + hi) >> 1;
+ if (list[mid] < want) lo = mid + 1;
+ else hi = mid;
+ }
+ g = list[lo];
+ if (lo > 0 && Math.abs(list[lo - 1] - want) <= Math.abs(g - want)) g = list[lo - 1];
+ }
+ }
+ pick[i] = g >= 0 ? path.join(dirs[Math.floor(g / 1e7)], frameName((g % 1e7) + 1)) : have.get(fk[i]);
+ if (g >= 0) off = g - i;
+ }
+
const next = path.join(chrome, `work-next-${stem}-frames`);
await rm(next, { recursive: true, force: true });
await mkdir(next, { recursive: true });
- for (let i = 0; i < fk.length; i += 1) await link(have.get(fk[i]), path.join(next, frameName(i + 1)));
+ for (let i = 0; i < fk.length; i += 1) await link(pick[i], path.join(next, frameName(i + 1)));
await writeFrameKeys(next, fk);
await writeFile(path.join(next, ".key"), key + "\n", "utf8");
const old = path.join(chrome, `work-old-${stem}-frames`);
diff --git a/umtool/report-to-video/frame-keys.test.mjs b/umtool/report-to-video/frame-keys.test.mjs
@@ -187,6 +187,13 @@ test("compose-chrome: a shifted stamp layer captures only its new keys, in one r
if (tag === oldTag) assert.equal(keys0[Number(cut)], keys1[i], `frame ${i + 1} reuses old frame ${Number(cut) + 1}, of its key`);
else assert.equal(keys1[Number(cut)], keys1[i], `frame ${i + 1} is the capture of a frame of its key`);
});
+ // A still stretch keeps its own frames: the end of the cut, moved 10
+ // frames, is the old end frame for frame -- not one frame of its key
+ // standing in for all (the renderer's workers draw a still a hair apart).
+ for (let i = 1150; i < 1210; i += 1) {
+ const [, cut] = readFileSync(path.join(framesDir, files[i]), "utf8").split(":");
+ assert.equal(Number(cut), i - 10, `frame ${i + 1} is old frame ${i - 9}`);
+ }
const log = readFileSync(path.join(out, "chrome", "renders.log"), "utf8").trim().split("\n");
assert.deepEqual(log[0], "whole 1200");
assert.match(log[1], /^list \d+$/, "one frame-list render");