# Image paste performance proof

Issue: [#42362](https://github.com/pingdotgg/t3code/issues/42362)
Base: [e6967d9dfe](https://github.com/pingdotgg/t3code/commit/e6967d9dfea689578f6cd9c83478bf651b9d8a60)
Head: [fbf3db9650](https://github.com/pingdotgg/t3code/commit/fbf3db96503648fb2ac814b5ad9fe1e25c72f6f4)

The scenario runner's Scenarios documentation excludes timing/performance regressions, so this uses the manual real-app path. No app source was changed and no unit tests are used as evidence.

## Environment and state

Both commits ran from separate installed worktrees, with fresh checkout-local databases, through `T3CODE_DEV_SEED=0 vp run dev`. Linux x86_64; Electron 44.10.1 / Chromium 152.0.7977.169; Xvfb through headless-desktop; --no-sandbox --disable-gpu; 1280x800 content viewport; light theme. No model turns were sent. The composer belongs to the dev server's newly bootstrapped project. A synthetic project was also registered with the app CLI on both sides. No real database or user content was used.

The measured requestAnimationFrame cadence is approximately 59.9 Hz. As in triage, 16 ms of synchronous work per frame models the no-idle ratio of 4 ms at 240 Hz. This does not claim a physical 240 Hz display was measured.

## Reproduce

Keep the scripts together in an empty directory. Set HEAD_WORKTREE, BASE_WORKTREE, HEAD_ORIGIN and BASE_ORIGIN to your installed checkouts and their printed web origins. The scripts call the side's CLI to mint a fresh pairing token and pair via the real UI; tokens and browser profiles are never included in this bundle.

Run the two dev servers first, each using T3CODE_DEV_SEED=0. Install Electron once in the head checkout with `node node_modules/electron/install.js` from apps/desktop.

```
REPO="$HEAD_WORKTREE" SERVER_REPO="$BASE_WORKTREE" ORIGIN="$BASE_ORIGIN" SIDE=before headless-desktop node driver.cjs
REPO="$HEAD_WORKTREE" SERVER_REPO="$HEAD_WORKTREE" ORIGIN="$HEAD_ORIGIN" SIDE=after headless-desktop node driver.cjs
```

Each run creates a new timestamped output directory. The driver pre-generates a synthetic PNG screenshot outside the timed interval, then dispatches a paste ClipboardEvent with a DataTransfer containing a fresh File on the composer's contenteditable. A MutationObserver records performance.now() from dispatch until the rendered Preparing span disappears, after first observing it. There are 12 pastes per configuration: the first is retained as warmup, followed by 11 samples for the reported median/min/max. No samples are deleted. All four configurations use the same method on both sides.

Busy work remains active for the entire timed paste. It is paused only after the label disappears, for output verification, capture and removing the tile. Output verification intercepts URL.createObjectURL to retain the real prepared File created by the composer; the driver decodes it for dimensions and hashes its complete contents. This instrumentation does not replace or call the app's compression functions.

The main artifact pair is before/ and after/. repeat-before/ and repeat-after/ hold the independent earlier runs. Every run's first paste and all recorded demonstration samples remain in its JSON. Two app screenshots 500 ms apart must be byte-identical before saving the summary still. The summary panel is driver-generated measurement output over the real app, not shipped UI. Captures crop the center of the actual 1280x800 app to 730x800, excluding environment identifiers. No composer content or status is redacted.

After the matrix, ffmpeg records three further real busy-page pastes per side. These are marked recordedSamples, separate from the unrecorded matrix so recording overhead cannot affect its medians.

## Compatibility

Install Pillow and pillow-heif, then generate synthetic HEIC inputs from source-large.png:

```
python3 make-heic.py source-large.png synthetic.heic
REPO="$HEAD_WORKTREE" SERVER_REPO="$BASE_WORKTREE" ORIGIN="$BASE_ORIGIN" SIDE=before headless-desktop node compatibility.cjs
REPO="$HEAD_WORKTREE" SERVER_REPO="$HEAD_WORKTREE" ORIGIN="$HEAD_ORIGIN" SIDE=after headless-desktop node compatibility.cjs
```

Compatibility cases are correctness checks on an idle page, three real composer pastes per case. They cover sRGB PNG, saturated Display P3 PNG, synthetic sRGB HEIC and synthetic Display P3 HEIC. The latter includes an out-of-sRGB green patch at the sampled corner. The normal head path, worker construction failure, missing worker OffscreenCanvas, missing OffscreenCanvas in both page and worker, and worker runtime failure are each exercised. A globally missing Worker is tested for both PNGs; HEIC depends on its separate third-party decoder worker, so its fallback is tested by making only T3's image worker fail construction. Faults are confined to the image worker except for the explicit globally missing Worker case. The missing-worker-canvas bootstrap buffers messages while importing the real worker module, then replays them, so none are lost during injection.

compatibility-before.json and compatibility-after.json hold all successful coverage. The after coverage was collected in two invocations (normal/no-worker/construction failure, then remaining missing-canvas/runtime-error modes). Original part JSON files are retained. Every output hash is compared with the corresponding base output; the merged results record the comparison. Display P3 pixels are read through a P3 canvas outside the timed interval. The HEIC P3 worker trace also records the colorSpace argument actually posted to the worker.

Busy-page performance is claimed only for the normal supported-worker path. Fallback coverage establishes successful preparation and equivalent output, not no-idle performance on a browser with the worker disabled. Native HEIC decoding on other operating systems was not exercised; Linux Chromium used the WASM decoder.

## Results

Primary busy large-image median: 1296.7 ms before, 164.5 ms after (7.88x faster; 87.3% less time). Ranges: 1249.6–1315.8 ms before, 153.7–179.6 ms after. The 1132.2 ms median improvement exceeds the sum of within-run ranges (92.1 ms). Independent earlier run: 1286.1 vs 170.2 ms. There is no common-case slowdown in either measured pair; first cold idle paste in the primary pair is 149.4 vs 140.4 ms.

The full prepared large PNG is 2000x1299, 161379 bytes, SHA-256 5468a6fbb675508291f9e09b87024b26a9a452b07cedc494eaa4a18f82404138, identical for every primary and repeat paste on both commits.
