# Preview stream performance proof

Base: 56d114d5168988d60dfde0919388aedbb206ac02
Head: 3313b1a3661250b3a547baa3802dfc00cdebb158

Run each commit in its own checkout with `vp i`. Use fresh state, with
`T3CODE_DEV_SEED=0 vp run dev`. Read the actual web/server ports. Do not seed
from another database. All content in these captures is synthetic.

## Fixtures and network

Put fixture-proxy.mjs and driver.js together in a fresh output directory for
this comparison. Create video.mp4 there with:

```sh
ffmpeg -f lavfi -i testsrc2=size=1078x1200:rate=60 -t 12 -c:v libx264 -preset ultrafast -crf 24 -pix_fmt yuv420p -movflags +faststart video.mp4
node fixture-proxy.mjs WEB_PORT PROXY_PORT
```

This serves the long page and 60 fps video at 127.0.0.1:18990 and proxies the
real app. Only `/api/preview-stream` WebSockets receive 40 ms in each direction.
TCP_NODELAY is enabled. Unlimited-bandwidth trials add no serialization delay.
Additional proxies use `NO_FIXTURE=1`. For the congestion comparison, also set
`BANDWIDTH_MBPS=1`; bytes are serialized in 1460-byte packets, rather than
holding an entire TCP read before delivery. For an IPv4-only backend, set
`UPSTREAM_HOST=127.0.0.1`.

## App setup and input

For web-hosted trials, add a project with the app's CLI and start a free replay
thread (no provider behavior is under test):

```sh
node apps/server/src/bin.ts project add --base-dir .t3 --title 'Stream performance' "$PROJECT_DIR"
node apps/server/src/bin.ts thread start --base-dir .t3 --provider devReplay --model multi-turn "$PROJECT_DIR" ready --title 'Stream measurement' --wait --json
```

Open the printed pairing link through the proxy port. Open the seeded thread
by its environment/thread URL. In the app, click Toggle right panel, Browser B,
and enter `http://127.0.0.1:18990/scroll` in Search or enter URL. The default
1280x800 client at DPR 2 produces a 539x675 CSS Browser canvas (1078x1350 target
pixels). Keep control, viewport, theme, and fixtures identical on both commits.

For Electron-hosted trials, build each checkout with
`vp run --filter @t3tools/desktop build:bundle`, install its Electron runtime
with `node apps/desktop/node_modules/electron/install.js`, and launch the real
built app from that checkout:

```sh
T3CODE_DEV_SEED=0 XDG_CONFIG_HOME="$ISOLATED_ELECTRON_CONFIG" T3CODE_HOME="$ISOLATED_T3_HOME" T3CODE_PORT="$BACKEND_PORT" headless-desktop apps/desktop/node_modules/electron/dist/electron --no-sandbox --disable-gpu --force-device-scale-factor=2 apps/desktop/dist-electron/main.cjs
```

Add the same project through the CLI, passing that isolated home as --base-dir.
Pair the web client to the desktop backend through a proxy. Open the project's
new-thread draft, then its Browser surface. No agent turn is necessary for this
surface. Server traces on both commits confirmed DesktopBrowserChannel
awaitAttached and endpoint succeeded. This exercises Electron-hosted browser
webContents, not headless Chromium standing in for Electron.

## Measurement and capture

After navigation finishes (the toolbar's Refresh button is visible), evaluate
in the real app client:

```js
await fetch('http://127.0.0.1:18990/driver.js').then(r => r.text()).then(s => (0, eval)(s));
await streamProof.run('base', 'scroll', 20);
await streamProof.run('base', 'scroll', 21);
await streamProof.run('base', 'scroll', 22);
```

Repeat with `head`, `desktop-base`, and `desktop-head`. Each trial reloads the
fixture and resets scrolling, waits for preparation, then sends wheel input at
60 Hz for 10 seconds. The 600–601 events each have deltaY 20 CSS pixels. Actual
scrolling is visible and advances through the same sections on both sides.

Navigate the Browser to `/video`, wait for Refresh, and repeat three trials with
mode `video`. Playback runs for 7.5 seconds without input during measurement.
The source file is a real H.264 video at 60 fps, not a simulated stream.

For congestion, use the 1 Mbps proxy and `/video`, then mode `congested`.
During 10 seconds of playback the driver sends six real editable-point probe
inputs over the authenticated preview WebSocket, awaiting each actual reply.
It does not release control or change the viewport. Completed base runs were
40, 42, 43; completed head runs were 40, 41, 42. Repeated reloads on base also
produced intermittent probe timeouts; these are disclosed, not counted as
successful responses.

The driver wraps CanvasRenderingContext2D.drawImage, records performance
timestamps for only the real Browser canvas, and writes both raw JSON and a
MediaRecorder capture of that canvas. Output filenames include side, action,
and trial number. Use new trial numbers/output directories for new comparisons.
FPS is (paint count - 1) / (last paint - first paint); gaps come from adjacent
paint timestamps. Reported numbers are medians of three runs, with full ranges;
p95 gap values in the summary are medians of each run's p95.

All comparisons use the same driver. The app's own adaptive motion resolution
is preserved: headless scrolling and Electron head downsample to 539x675;
Electron base remains at 1078x1350. Passive video stays at 1078x1350.

Calibration runs using outer-tab recording were discarded because the second
stream/encoder depressed FPS. Early bandwidth calibration held whole TCP reads
and was discarded after changing to packet serialization. Final retained runs
and their exact timestamp arrays are in measurements.json.

## Result

The RTT and desktop ceilings reproduce, and head is faster by far more than
run spread. Scrolling reached about 30 fps here, not the claimed 60 fps. The
healthy video result is about 30 fps. Congested video remains about 1.64 fps
on both commits; completed control probes remain bounded below one frame's
roughly 612 ms transfer interval. This does not prove every network condition.
