# Web build: WebAssembly, isolation, caching and compression
## Decision
The installed web app is built with `flutter build web --wasm`
(`app/docker/build.sh`): dart2wasm + skwasm in Chromium-based browsers with
WasmGC and WebGL (Flutter's loader allows wasm only on Blink by default), and
the dart2js + CanvasKit build beside it, which the loader picks otherwise
(Firefox, Safari, no WebGL). The proxy serves the app
cross-origin isolated (COOP `same-origin`, COEP `credentialless`), so skwasm
renders on a worker thread.
`credentialless`, not `require-corp`: a sandboxed HTML artifact (srcdoc
iframe, which inherits the page's COEP) and chat markdown can show images
from other sites that send no Cross-Origin-Resource-Policy. Checked in the
browser: an HTML artifact with a cross-origin, no-CORP `
` still renders
under isolation. The WebSocket, same-origin `/artifacts/` fetches, video and
the Roboto fallback font from fonts.gstatic.com (CORS) are unaffected
(WebSocket against a live server not exercised here).
## Compatibility
- Our own web code already used `dart:js_interop`/`package:web`; the wasm
dry run reported only `flutter_tts`'s web plugin (`event['charIndex'] as
int`, a `JSAny` error payload sent over a method channel). Both break word
highlighting and error reports under wasm, so the web now uses
`lib/features/chat/speech/web_speech_engine.dart` (Web Speech API through
`package:web`, same behaviour as the plugin). The plugin still registers
on the web, so the dry-run warning remains. Read aloud with real voices
under wasm is unverified: headless Chrome has no voices.
- `app/web/flutter_bootstrap.js` registers no service worker (Flutter's is
deprecated; it only unregistered itself and reloaded the page, a second
startup after every install).
## Serving (web/src/appFiles.js)
- An installed build has `release.json`; the shell page gets
`` and the
bootstrap loads the entrypoint, renderer and assets from there. Those
responses are `private, max-age=31536000, immutable`. Another build's id
(a tab left open over an install) gets the current file, `no-cache`.
- The shell is `no-store`; every other file is `no-cache` with an ETag (304).
- `scripts/precompress_web.mjs` (run by `scripts/app_build.py`, cached with
the build) writes `.br`/`.gz`; the proxy sends them by `Accept-Encoding`.
main.dart.wasm 4.8 MB -> 1.4 MB br, skwasm.wasm 3.6 -> 1.2, main.dart.js
5.3 -> 1.2, canvaskit.wasm 7.2 -> 2.2. A first load on wasm transfers about
2.7 MB instead of 12.5 MB uncompressed JS + CanvasKit.
- A reload transfers only the shell and a 304 for flutter_bootstrap.js.
- `./install --web` installs the build; the proxy (`lib/web`) changes take
effect after a full install restarts it. The new build also works behind the
old proxy (no isolation: skwasm single-threaded; no immutable caching).
## Measurements (2026-12-01, Linux, RTX 2080 Ti, Chromium 155, load avg 10-20)
`tool/perf/interaction_bench.mjs --gpu --repeat 3 --memory` over the probe
fixture (release builds), medians. A = JS/CanvasKit as installed before (with
the service-worker registration), B = JS with the new bootstrap and isolation,
C = wasm without isolation, D = wasm isolated (what is installed now).
| scenario | metric | A js | B js+iso | C wasm | D wasm+iso |
| --- | --- | --- | --- | --- | --- |
| startup | first frame ms | 784 | 479 | 262 | 318 |
| startup | build sum ms | 184 | 109 | 49 | 73 |
| chat list -> open chat | build sum / longest ms | 48.9 / 21.4 | 22.1 / 9.6 | 6.3 / 3.5 | 8.6 / 22.1 |
| scroll a rich chat | build sum / max ms | 426 / 33.7 | 312 / 20.4 | 113 / 9.4 | 110 / 10.1 |
| scroll a rich chat | frames over 16 ms | 7 | 6 | 0 | 0 |
| switch chat | build sum / longest ms | 171 / 53.6 | 133 / 38.2 | 56 / 12.1 | 59 / 25.8 |
| open terminal panel | build sum / longest ms | 263 / 65.9 | 298 / 79.5 | 143 / 28.7 | 146 / 35.5 |
| tab runs -> chat (150) | build max / longest ms | 130 / 139 | 78 / 82 | 33 / 35 | 36 / 56 |
| memory | Chrome RSS after scroll, MB | 1477 | 1398 | 1332 | 1306 |
Build (UI thread) time drops 2-4x with wasm. With isolation, skwasm's raster
runs on a worker, so its reported raster time (and frame span) includes the
hand-off; the main thread is what stays free. The terminal stream bench
(headless, no `--gpu`, 30 MB per workload) shows that directly in the page's
own rAF intervals (ms):
| workload | js rAF p99 / max | wasm rAF p99 / max | wasm+iso rAF p99 / max | build p50 js / wasm |
| --- | --- | --- | --- | --- |
| seq | 33.3 / 66.6 | 33.3 / 33.3 | 16.7 / 16.7 | 2.3 / 1.0 |
| yes | 16.8 / 49.9 | 16.8 / 33.3 | 16.7 / 16.7 | 1.5 / 0.6 |
| unicode | 116.7 / 166.7 | 49.9 / 100.1 | 33.3 / 66.7 | 3.0 / 1.2 |
| colors | 33.4 / 50 | 16.8 / 33.2 | 16.7 / 16.7 | 2.6 / 1.2 |
| screen | 33.3 / 66.7 | 16.8 / 33.3 | 16.7 / 16.7 | 3.6 / 2.1 |
Headed Chromium on Xvfb has no WebGL, so the wasm build fell back to
CanvasKit there (confirming the fallback); its numbers equal the JS build's.
Headless without `--gpu` still had WebGL (SwiftShader), so skwasm ran.
The machine was shared with other agents' builds and tests; compare columns,
not absolute values.