Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(render-farm): keep decoder readahead off so opening frames are not held
Richie McIlroyda0427680242
diff --git a/apps/render-farm/README.md b/apps/render-farm/README.mdindex cc68c96a8..498dd5fe4 100644--- a/apps/render-farm/README.md+++ b/apps/render-farm/README.md@@ -94,7 +94,7 @@ expires `hls/` and `jobs/` objects.| `RF_JOB_STALL_MS` / `RF_JOB_RETENTION_MS` | 10 min / 1 h | Job watchdog and summary retention || `RF_STALL_MS` | `30000` | Worker engine watchdog || `RF_DRAIN_MS` | 15 min | Longest a `SIGTERM` drain may take |-| `CAP_DECODER_READAHEAD` | `8` | Frames each decoder decodes ahead of the renderer |+| `CAP_DECODER_READAHEAD` | `0` | Frames each decoder decodes ahead of the renderer. Leave off until the decoder's readahead keeps the first frames of a clip (see the worker's `engineEnv`) || `RF_HOT_SWAP` | off | Development: pull the engine, app and tuning from the bucket's `bin/` pointers |## Product integrationdiff --git a/apps/render-farm/src/worker.test.ts b/apps/render-farm/src/worker.test.tsindex 8038a359e..ca6be0e19 100644--- a/apps/render-farm/src/worker.test.ts+++ b/apps/render-farm/src/worker.test.ts@@ -81,13 +81,16 @@ function harness(const compiled = new Bun.Transpiler({ loader: "ts" }).transformSync(source);const worker = new Function(...Object.keys(deps),- `${compiled}\nreturn {runTranscode, cancel, busy, progress, transcoders};`,+ `${compiled}\nreturn {runTranscode, cancel, busy, progress, transcoders, engineEnv};`,)(...Object.values(deps)) as {runTranscode: (task: TranscodeTask, slot: number) => Promise<number>;cancel: (taskIds: string[]) => void;busy: Map<number, WorkItem>;progress: Map<number, { lastProgressAt: number }>;transcoders: Map<number, unknown>;+ engineEnv: (+ env: Record<string, string | undefined>,+ ) => Record<string, string>;};return {...worker,@@ -160,3 +163,13 @@ describe("transcode cancellation", () => {expect(h.progress.size).toBe(0);});});++describe("engine environment", () => {+ test("keeps decoder readahead off unless the deployment sets it", () => {+ const h = harness();+ expect(h.engineEnv({}).CAP_DECODER_READAHEAD).toBe("0");+ expect(+ h.engineEnv({ CAP_DECODER_READAHEAD: "4" }).CAP_DECODER_READAHEAD,+ ).toBe("4");+ });+});diff --git a/apps/render-farm/src/worker.ts b/apps/render-farm/src/worker.tsindex 7853521ea..cf33ee195 100644--- a/apps/render-farm/src/worker.ts+++ b/apps/render-farm/src/worker.ts@@ -60,18 +60,28 @@ const headers = {...(TOKEN ? { authorization: `Bearer ${TOKEN}` } : {}),};+/**+ * Engine environment. Decoder readahead stays off by default: with it on,+ * the first chunk of a clip can hold the recording's opening frame for+ * seconds, because the readahead window overfills the decoder's frame cache+ * before the first request and every later request falls behind it.+ */+function engineEnv(env: Record<string, string | undefined>) {+ return {+ LP_NUM_THREADS: String(THREADS),+ RAYON_NUM_THREADS: String(THREADS),+ CAP_EXPORT_DISABLE_ZERO_COPY: "1",+ CAP_RENDER_LOOP_STATS: "1",+ CAP_DECODER_READAHEAD: env.CAP_DECODER_READAHEAD ?? "0",+ };+}+const engines = Array.from({ length: SLOTS + AUDIO_SLOTS },(_, slot) =>new Engine(ENGINE_BIN,- {- LP_NUM_THREADS: String(THREADS),- RAYON_NUM_THREADS: String(THREADS),- CAP_EXPORT_DISABLE_ZERO_COPY: "1",- CAP_RENDER_LOOP_STATS: "1",- CAP_DECODER_READAHEAD: process.env.CAP_DECODER_READAHEAD ?? "8",- },+ engineEnv(process.env),`slot${slot}`,// Studio Sound lanes are CPU-heavy; on a 4 vCPU host they would// otherwise starve the render slots' decode/encode threads.