Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

perf(poc): measure throughput, not the empty loop — and serialise the encoder on this iGPU

Etienne Lescota0c3886fd715
diff --git a/docs/architecture/rendering-architecture.md b/docs/architecture/rendering-architecture.md
index f1c27e000..9f101632c 100644
--- a/docs/architecture/rendering-architecture.md
+++ b/docs/architecture/rendering-architecture.md
@@ -633,6 +633,44 @@ Every one of these produced a confident, wrong number first:
everything else combined, on a long-GOP screen recording. Forward streams: 0.6.
- **The harness leaked its GPU device**, and six back-to-back runs decayed
19.9 → 8.6 → 7.5 fps during the very A/B meant to settle a question.
+- **Per-loop fps measured an empty loop, not throughput.** Under the pipeline the
+ loop does not wait for the work — `submit()` is non-blocking, encode is awaited
+ only on backpressure — so a SLOWER composite blocks the loop LESS and reads
+ FASTER: the naive arm reported 588 fps, 5× the optimised arm's, doing more work.
+ Throughput is now frames ÷ wall until they are actually composited, encoded and
+ muxed (finalize() forces completion), which is immune to the artifact. The
+ product owner caught this one from the numbers alone.
+
+### C.3 — Pipelining the encoder LOSES on this iGPU (measured 2026-07-17)
+
+§11 says "pipeline, don't await": keep the encoder queue full so the compositor
+and the encoder overlap. Measured on the reference integrated GPU, with the
+corrected throughput metric, interleaved A/B, spread 7–11 % (so real):
+
+| encoder queue depth | throughput |
+|---|---:|
+| 4 (buffered / pipelined) | 49 fps |
+| 1 (serialised, await each frame) | **79 fps** |
+
+**Pipelining is 38 % SLOWER here, not faster.** The likely cause is that an
+integrated GPU shares one memory bus between the WebGPU compositor and the
+fixed-function H.264 encoder: overlapping them makes them contend for bandwidth,
+where serialising lets each have it in full per turn. (A first, larger "gain"
+from pipelining — +205 % — was the empty-loop artifact of C.2, not real.)
+
+Consequence, now the default: **serialise the encoder on integrated GPUs.** The
+pipeline path stays reachable behind a `queueDepth` override because a DISCRETE
+GPU — separate encoder silicon, dedicated VRAM — may well flip this, and that is
+exactly the discrete-GPU run still owed (bench G3). §11's rule is not wrong in
+general; it is wrong for the memory topology of the weakest, most common machine,
+which is the one the whole document optimises for.
+
+The honest, trustworthy rate for the POC is therefore **~79 fps at 1080p30**, all
+effects on, serialised, on the reference iGPU — comfortably past 60. The frame is
+**encoder-bound**: the compositor's own GPU pass is 1.9 ms (C, throttle-immune),
+and the encode is the largest remaining slice, so the next levers are the
+encoder's (bitrate/preset, and segment-parallel encode across GOPs — which needs
+multiple encoder instances, not a deeper queue on one), not the shader's.
---
diff --git a/poc/index.html b/poc/index.html
index 3a4343afa..a72fe2ccf 100644
--- a/poc/index.html
+++ b/poc/index.html
@@ -56,7 +56,9 @@
<div>
<label for="compareMode">comparer</label>
<select id="compareMode" style="width: auto; min-width: 210px; background: #22222c; color: #e8e8ee; border: 1px solid #33333f; border-radius: 6px; padding: 6px 8px; font-size: 13px;">
+ <option value="pipeline">Pipeline : bufférisé vs sérialisé</option>
<option value="perf">Perf : optimisé vs naïf</option>
+ <option value="encode">Encodage : avec vs sans</option>
<option value="effects">Effets : activés vs coupés</option>
<option value="instruments">Mesure : instrumenté vs propre</option>
</select>
diff --git a/poc/main.js b/poc/main.js
index 1d65ce149..a7b06d654 100644
--- a/poc/main.js
+++ b/poc/main.js
@@ -462,11 +462,35 @@ async function run(override = {}) {
// only exists while being measured.
const instrumented = override.instrumented ?? document.querySelector("#instrument").checked;
const optimised = override.optimised ?? document.querySelector("#optimise").checked;
+ const encodeOn = override.encode ?? true;
+ // How many encodes may be in flight before composite blocks.
+ //
+ // Default 1 (serialised) BECAUSE IT IS FASTER HERE, measured: buffered depth-4
+ // throughput 49 fps vs serialised 79 fps on this iGPU (spread 7-11%, so real).
+ // §11's "pipeline, don't await" assumed overlap helps; on an integrated GPU the
+ // compositor and the hardware H.264 encoder share one memory bus, so running
+ // them at once makes them contend rather than parallelise — serialising lets
+ // each have the full bandwidth in turn. The pipeline stays reachable
+ // (queueDepth override) because a DISCRETE GPU, with its own VRAM and separate
+ // encoder silicon, may flip the result — untested (that is bench G3).
+ const queueDepth = instrumented ? 1 : (override.queueDepth ?? 1);
+ const inflight = [];
const frames = [];
const t0 = performance.now();
+ // The steady-state window starts after the first quarter (warm-up). We time it
+ // on the WALL, from here to after the final drain+flush — not per loop
+ // iteration — because with the pipeline the loop does not wait for the work:
+ // submit() is non-blocking and encode is only awaited on backpressure. A
+ // per-frame timer then measures an empty loop distributing orders (naive
+ // composite is slower, so it feeds the encoder slower, so the loop blocks LESS
+ // and reads FASTER — 588 fps of nothing). True throughput is frames ÷ the wall
+ // until they have actually completed, which finalize() forces.
+ const warmStart = Math.ceil(totalFrames / 4);
+ let warmWall = 0;
let rendered = 0;
for (let i = 0; i < totalFrames; i++) {
+ if (i === warmStart) warmWall = performance.now();
const t = i / OUT.fps;
const fStart = performance.now();
const p = {};
@@ -614,12 +638,32 @@ async function run(override = {}) {
}
}
+ // ENCODE — pipelined, not awaited per frame.
+ //
+ // source.add snapshots the canvas synchronously (new VideoSample(canvas)),
+ // and everything rides one GPU queue, so submission order already guarantees
+ // each encoded frame reflects its own composite — no fence needed for
+ // correctness. Awaiting add() every frame only enforces BACKPRESSURE, and
+ // doing it per frame is what serialised the loop: composite waited on the
+ // encoder accepting the previous frame. Keep `queueDepth` frames in flight
+ // instead, so the hardware encoder runs concurrently with the next
+ // composite. This is §11 — pipeline, don't await.
m = mark();
- await source.add(t, 1 / OUT.fps);
+ if (encodeOn) {
+ const addP = source.add(t, 1 / OUT.fps);
+ if (queueDepth <= 1) {
+ await addP;
+ } else {
+ inflight.push(addP);
+ if (inflight.length >= queueDepth) await inflight.shift();
+ }
+ }
p.encode = mark() - m;
- // The VideoFrames are ours; the samples belong to the streams, which close
- // them when they advance.
+ // The decode VideoFrames are ours; the samples belong to the streams, which
+ // close them when they advance. Safe to close after submit: Chromium holds
+ // its own reference to an imported external texture until the submit that
+ // used it completes.
screenFrame.close();
webcamFrame?.close();
@@ -642,8 +686,19 @@ async function run(override = {}) {
}
}
- const wallMs = performance.now() - t0;
+ // Drain the encoder pipeline, then flush+mux: only after finalize() has all
+ // frames actually completed. The throughput window closes HERE, not at the end
+ // of the loop, because the loop returns before the GPU and the encoder are
+ // done.
+ if (inflight.length) await Promise.all(inflight);
await output.finalize();
+ const endWall = performance.now();
+ const wallMs = endWall - t0;
+ // The honest steady-state throughput: frames rendered after warm-up, over the
+ // wall time until they are fully composited, encoded and muxed.
+ const warmFrames = rendered - warmStart;
+ const throughputFps =
+ warmWall > 0 ? warmFrames / ((endWall - warmWall) / 1000) : rendered / (wallMs / 1000);
// ---- report ----
//
@@ -659,14 +714,17 @@ async function run(override = {}) {
const totals = frames.map((f) => f.total);
// Cruise = the steady state: drop the first quarter, then take the MEDIAN, so
// one scheduler hiccup cannot move the number.
- const warm = frames.slice(Math.ceil(frames.length / 4));
+ const warm = frames.slice(warmStart);
const cruiseMs = median(warm.map((f) => f.total));
const cruiseFps = 1000 / cruiseMs;
const avgFps = rendered / (wallMs / 1000);
- setStat("fps", cruiseFps.toFixed(1));
+ // Throughput is the headline. Cruise (per-frame loop time) is kept for the
+ // instrumented breakdown, where the fence makes each iteration wait for its own
+ // work — there it equals throughput; under the pipeline it does not.
+ setStat("fps", throughputFps.toFixed(1));
setStat("progress", `${rendered}/${totalFrames}`);
- setStat("perframe", `${cruiseMs.toFixed(1)} ms`);
+ setStat("perframe", `${(1000 / throughputFps).toFixed(1)} ms`);
// `?? 0`: the clean pass has no phase timers by construction — that is what
// makes it clean. Reading them back as undefined is not an error, it is the
// point.
@@ -675,7 +733,10 @@ async function run(override = {}) {
setStat("encode", instrumented ? `${median(warm.map((f) => f.encode ?? 0)).toFixed(1)} ms` : "—");
log(
- `\n=== [${instrumented ? "INSTRUMENTED" : "CLEAN"}] cruise ${cruiseFps.toFixed(1)} fps — ${cruiseMs.toFixed(1)} ms/frame (median of the last ${warm.length}) ===`,
+ `\n=== [${instrumented ? "INSTRUMENTED" : "CLEAN"}] throughput ${throughputFps.toFixed(1)} fps — ${warmFrames} frames in ${((endWall - warmWall) / 1000).toFixed(2)}s (wall, incl. drain+mux) ===`,
+ );
+ log(
+ `per-loop cruise ${cruiseFps.toFixed(1)} fps (${cruiseMs.toFixed(1)} ms) — under the pipeline this measures the LOOP, not completion; throughput above is the honest number.`,
);
log(
`average ${avgFps.toFixed(1)} fps over all ${rendered} frames (${(wallMs / 1000).toFixed(2)}s wall)`,
@@ -751,7 +812,7 @@ async function run(override = {}) {
device.destroy();
document.querySelector("#run").disabled = false;
- return { cruiseMs, cruiseFps, avgFps, instrumented };
+ return { cruiseMs, cruiseFps, avgFps, throughputFps, instrumented };
}
/**
@@ -783,6 +844,18 @@ const COMPARISONS = {
b: { label: "effets OFF", over: { effectsOn: false, optimised: true, instrumented: false } },
note: "ombre + flou de fond présents, vs à zéro. Le prix des effets eux-mêmes.",
},
+ pipeline: {
+ title: "Pipeline : bufférisé vs sérialisé",
+ a: { label: "bufférisé", over: { queueDepth: 4, instrumented: false, optimised: true } },
+ b: { label: "sérialisé", over: { queueDepth: 1, instrumented: false, optimised: true } },
+ note: "encodage recouvert (4 en vol) vs attendu à chaque image. Le levier §11.",
+ },
+ encode: {
+ title: "Encodage : avec vs sans",
+ a: { label: "avec encodage", over: { encode: true, instrumented: false, optimised: true } },
+ b: { label: "sans encodage", over: { encode: false, instrumented: false, optimised: true } },
+ note: "compose + encode vs compose seul. Ce que coûte l'encodeur matériel.",
+ },
instruments: {
title: "Mesure : instrumenté vs propre",
a: { label: "instrumenté", over: { instrumented: true, optimised: true } },
@@ -820,7 +893,7 @@ async function compare(rounds = 3) {
for (let r = 0; r <= rounds; r++) {
for (const arm of arms) {
const res = await run(arm.over);
- if (r > 0) arm.runs.push(res.cruiseFps);
+ if (r > 0) arm.runs.push(res.throughputFps);
}
}
@@ -829,7 +902,7 @@ async function compare(rounds = 3) {
log(`${spec.note}\n`);
for (const arm of arms) {
log(
- `${arm.label.padEnd(13)} croisière ${median(arm.runs).toFixed(1).padStart(5)} fps spread ${(spread(arm.runs) * 100).toFixed(0)}% ${arm.runs.map((x) => x.toFixed(1)).join(" / ")}`,
+ `${arm.label.padEnd(13)} débit ${median(arm.runs).toFixed(1).padStart(5)} fps spread ${(spread(arm.runs) * 100).toFixed(0)}% ${arm.runs.map((x) => x.toFixed(1)).join(" / ")}`,
);
}
const [A, B] = arms;
@@ -839,12 +912,25 @@ async function compare(rounds = 3) {
log(
`\n${A.label} vs ${B.label}: ${gain > 0 ? "+" : ""}${gain.toFixed(1)} fps (${gainPct.toFixed(0)}%)`,
);
- if (worst >= Math.abs(gainPct)) {
+ // Two gates, not one. The old gate only checked spread against the EFFECT, so a
+ // big effect waved through big noise — a 66% spread "held" against a 205% gain
+ // while the tab was throttled and the arm swung 117→235 fps. An ABSOLUTE
+ // threshold catches that: above ~15% same-arm spread the machine is not steady
+ // enough to trust the magnitude, whatever the effect size. (The app's export
+ // bench uses 10%; this browser setup is noisier, so 15%.)
+ const SPREAD_LIMIT = 15;
+ if (worst >= SPREAD_LIMIT) {
log(
- `\n!! VOID : spread intra-bras ${worst.toFixed(0)}%, aussi grand que l'effet.\n Ce run ne dit rien — refaire sur une machine calme.`,
+ `\n!! VOID : spread intra-bras ${worst.toFixed(0)}% > ${SPREAD_LIMIT}% — la machine dérive.` +
+ `\n La DIRECTION peut tenir (regarde si un bras gagne à chaque tour), mais` +
+ `\n le CHIFFRE ne vaut rien. Ferme les autres apps GPU, secteur branché, refais.`,
);
+ } else if (worst >= Math.abs(gainPct)) {
+ log(`\n!! VOID : spread intra-bras ${worst.toFixed(0)}%, aussi grand que l'effet — run muet.`);
} else {
- log(`\nspread intra-bras ${worst.toFixed(0)}% < l'effet — le résultat tient.`);
+ log(
+ `\nspread intra-bras ${worst.toFixed(0)}% < ${SPREAD_LIMIT}% et < l'effet — le résultat tient.`,
+ );
}
setStat("fps", median(A.runs).toFixed(1));
}