# Browser latency and recovery

## Profile compatibility — Browser Preview 7

The Preview 7 client negotiates a supported encode profile before a
session and retries another profile if the actual headers are rejected. It keeps
the chosen resolution and bitrate while permitting Main10 → Main8 → AV1 → H.264
fallback. HDR output is gated separately from decode support. See
[profile negotiation and its verification scope](browser-client.md#profile-negotiation-browser-preview-7).

## Full-quality transport and codec work — local, unreleased

The selected resolution is fixed for the lifetime of a browser session. Quality
messages may change only the bitrate; a different width or height is rejected by
the Host protocol, and the gateway never emits dimensions in an adaptation
request. This closes the earlier automatic fallback to a smaller picture. That
older candidate reached 960×540 under controlled loss and is superseded, not an
accepted full-quality result.

Bitrate reduction is disabled by default and starts only when the user explicitly
enables it for a session on a supported encoder. It must not be described as
quality-neutral: a lower target can reduce visible detail even when resolution
and frame rate stay fixed. A bitrate target is not a hard wire-rate limit.
Statistics distinguish the acknowledged target, the user's ceiling, and measured
encoded payload arriving at the gateway.

The browser now derives every decoder configuration from the actual keyframe
instead of passing literal `h264` or `hevc` labels to WebCodecs. The HEVC path
parses profile-tier-level metadata, compatibility and constraint flags, coded
and cropped dimensions, chroma format, and bit depth; it constructs the codec
string and a complete `hvcC` description containing VPS, SPS, and PPS NALs.
Keyframes and deltas are converted from Annex B to the canonical length-prefixed
access-unit format required when that description is present.
The Host requests HEVC Main10 only when its encoder capabilities include 10-bit
mode, and rejects that request otherwise. H.264 remains 8-bit SDR. The OpusHead
used by Preview 4 is unchanged.

Source checks use genuine x265 Main and Main10 parameter sets from the native
Client fixtures, including 1280×736 coded pictures cropped to 1280×720. These
checks cover parser and `hvcC` layout behavior, not a 4K VAAPI capture or Chrome
runtime acceptance. Full-quality browser/native fidelity and controlled-loss
results remain separate pending measurements.

The transport preserves compressed-frame dependencies:

- A bounded six-frame / 8 MiB encoded queue retires a broken reference chain.
  It waits for an IDR instead of forwarding unusable dependent pictures, while
  preserving a newer queued IDR when an older in-flight picture fails.
- Video uses a reliable ordered WebTransport stream with 2000 ms delta and
  8000 ms IDR write deadlines. A source-contained congestion controller retains
  a bounded 1 MiB minimum window instead of collapsing the stream to a lower
  bitrate after isolated packet loss. Audio and input retain datagram delivery.
  The reorder buffer is bounded to 16 MiB and 9000 ms. Audio assembly expires at
  40 ms. Completed frames are delivered immediately; these are expiry bounds,
  not fixed playback delays. Expired IDs are retired so late fragments cannot
  repeatedly resurrect an incomplete picture.
- Audio datagrams use three Reed–Solomon parity shards per eight-fragment group
  to recover up to three missing fragments. The original XOR shard is retained as shard zero, with two
  projective Cauchy recovery shards added. Four or more missing fragments expire
  rather than delivering corrupt media. Short final groups use zero padding only
  for parity math and do not expand audio packets.
- Audio uses its own bounded queue/sender. A large video access unit no longer
  owns the entire media-send loop. The previously corrected AudioWorklet is
  unchanged.
- A send blocked inside QUIC for over two seconds cancels the dedicated,
  unpooled browser connection, releasing both media senders and the Host session.
  Host keyframe requests arriving during its throttle are coalesced rather than
  silently discarded.

The original sender reproduced a one-frame/ten-second timeout at 20 ms RTT,
100 Mbps downstream cap and 1% packet loss. A clean private 4K60 Main10 run passed
with 59.98 steady decoded/rendered FPS, zero presentation drops, all 3751 displayed
CRC samples valid, and zero silent 5 ms audio windows. The final 60-second run at
the original loss settings sustained 59.996 decoded/rendered FPS at fixed
3840×2160 / 60 Mbps, with zero presentation drops, zero silent 5 ms audio windows,
and 7501/7501 valid displayed CRC samples. There were nine transport drops and
one reset during that run, but no steady resyncs.

A valid native H.264 control at the same settings reported 60.22 incoming, 60.22
decoded, and 60.05 rendered FPS, with nonzero video, audio, and control proxy
interception. Its displayed-image age was 69 ms mean versus 115 ms for the browser
under loss, so latency parity is not established. These are controlled loopback
fixtures, not measurements of the customer's home network, physical 4K scanout,
or input-to-photon latency. No release or installation has occurred.

## High-resolution rendering isolation

Preview3 moves canvas conversion/drawing off the transport/decoder worker. At4K,
software drawing can occupy roughly15ms of a16.7ms frame budget, delaying input,
packet intake and decoder-output callbacks. The renderer now receives decoded
VideoFrames over a direct MessagePort. Its credited mailbox holds one transferred
frame plus one replaceable pending frame; superseded frames are closed promptly.
Only presentation work is dropped, preserving compressed-video reference chains.
The DOM-bound canvas is transferred directly from the page once, avoiding Firefox's
re-transfer restriction. A failed renderer startup cancels its unused reservation.

The status line adds **FPS** (acknowledged canvas draws, not monitor scanout),
**draw** (canvas call wall time, not GPU completion), **pending decode/render**, and
**superseded** decoded presentations. Render work is kept bounded even when a
device cannot sustain the requested FPS. Control RTT excludes the initial setup
ping; steady samples still include transport and Host processing.

Controlled software tests used noisy pre-encoded H.264 at4K60 and actual payloads
around51/81Mbps through the real helper, WebTransport and WebCodecs. At80Mbps,
input-dispatch→synthetic-Host p95 improved18.7→about0.5ms and sender-timestamp→draw
return mean62.2→31.8ms; typical output windows improved45→56pictures/second. With
20ms emulated RTT/300Mbps path, draw-return mean87.1→46.5ms and typical windows
33→54pictures/second. These are software pipeline measurements, not physical
input-to-photon, display scanout or customer GPU/WAN qualification.

Full private-Host4K image readback also verified actual visible rendering, but its
software capture/encoding path delivered only about30FPS. Native image age was
140ms median/180ms p95; original browser160/188ms and candidate153/182ms in those
runs. The source itself was delayed; these results do not establish a material
end-to-end video reduction or native parity in a Host-bound workload. Input enqueue
delay nevertheless fell from roughly25–30ms p95 to below1ms there. Firefox720p
visible rendering passed all326 clock/checksum samples.

Increasing the receive buffer alone did not fix the4K bottleneck. Separate
bitmaprenderer and smaller-canvas experiments were slower and were rejected.
Actual browser hardware acceleration, display refresh and sustainable stream
capacity still matter.27JavaScript checks cover the retained input/media logic
and bounded frame ownership, and real failed-renderer startup verifies cleanup.

## Preview 2 input improvements

Preview2 removes an avoidable display-frame wait from mouse input. Movement is
forwarded on input events, with native-like1ms coalescing for high-rate motion and
a bounded latest-value mailbox between the page and worker. A fresh gesture is
not delayed behind an idle housekeeping packet. Unlocked mouse input uses
`pointerrawupdate` where available; pointer-lock mode uses its compatible mouse
event path without double-counting the associated pointer events.

Controller polling is independent of video animation frames, and unchanged
controller labels no longer replace DOM content on every frame. Reliable keyboard
and button edges, cumulative motion recovery and focus/disconnect neutralization
are retained. Short absolute-position retries end after idle rather than repeatedly
overriding a cursor moved on the Host.

WebTransport now requests unreliable delivery and the browser's low-latency
congestion preference. Supported datagram-age/buffering controls bound stale input.
These settings are browser capabilities/hints; they do not change the server's
congestion-control algorithm or guarantee a particular network delay.

## Reading the diagnostics

- **Control RTT:** application ping round trip through the transport and Host
  input-processing path. Includes scheduling/queueing, not just network propagation.
- **Input queue p95:** recent page-dispatch-to-worker-datagram-enqueue delay.
  It excludes OS event delivery, the network and the remote game/display response.
- **Decode/output:** encoded-frame submission to the WebCodecs output callback,
  including decoder buffering and callback scheduling. It is not GPU-only time.
- **Pending:** submitted frames that have not produced decoder output. This
  exposes buffering hidden by `decodeQueueSize` alone.
- **FEC repairs / expired:** network-frame recovery/expiry counters.
- **Target / limit:** acknowledged session bitrate target and the user's ceiling.
  Resolution remains fixed at the selected value.
- **Encoded:** H.264 or HEVC payload rate arriving from the Host, before gateway drops and
  transport overhead. It can exceed the requested encoder target.
- **Transport drops:** compressed pictures retired at the gateway, including
  dependents of a lost reference. This is separate from network expiry and
  superseded decoded presentations.

These metrics are not physical input-to-photon latency. Browser draw completion
does not establish when a monitor scanned out a frame.

## Comparing with the native client

1. Use the same Host, resolution, FPS, bitrate, codec and bit depth. The browser
   supports H.264 8-bit SDR and HEVC Main10 when the Host advertises 10-bit support.
2. Compare the same mouse mode. Use **Capture mouse** for relative/raw game input,
   matching the usual native-client capture mode. Fullscreen avoids unnecessary
   desktop scaling and makes refresh-rate differences easier to identify.
3. Check display refresh and sustainable FPS.120FPS can reduce sampling delay on
   capable systems, but also needs more encoding/decoding/network capacity.
4. Keep **Automatic (hardware preferred)** initially. If decode/output delay or
   pending frames stay high, reconnect with **Browser default** and **Software
   preference** to compare actual results. Hardware preferences are hints, not
   proof of which decoder the browser used; forcing software can be slower.
5. Chromium's Media panel can identify decoder behavior. Close diagnostic tools
   before judging normal responsiveness, since profiling/layout changes can affect
   measurements. Working browser graphics/video acceleration is device-specific.
6. Keep bitrate below the sustainable path capacity. Wi-Fi jitter/bufferbloat and
   fixed-rate encoding under congestion can dominate both input and video latency.

## Verified scope

Original-source and final-candidate synthetic DOM input checks used real Chromium
and Firefox on an isolated Linux runtime. At~60Hz, the original mouse dispatch
wait was approximately8ms median/16ms p95. Final Chromium p95 was0.1ms; Firefox
p95 was below its timer resolution. This measures only the application scheduling
stage, not total latency or a physical mouse.

Matched1280×720/60FPS/H.264/4Mbps software capture/decoding tests used an in-image
monotonic clock and private X11 readback. With20ms emulated RTT, the native client
measured23ms median/30ms p95 image age; the final browser candidate measured25/33ms.
All326 samples per stream passed barcode/complement/checksum validation. Native
used VSync off. These are controlled software results, not universal native-client
parity, physical display latency or customer-GPU certification.

Direct main-thread canvas presentation was also tested; it did not consistently
improve the established worker renderer and is not included. Forcing software
decoding was not consistently faster, so it remains a comparison option rather
than the default. Browser compositor/driver behavior and different hardware codecs
remain possible sources of a gap on an individual viewing device.

## Research and further work

Reviewed input dispatch/coalescing, worker boundaries, codec/SPS/VUI behavior,
decoder queues, canvas/WebGL/WebGPU/video presentation, FPS/VSync, capture/encoder
settings, IPC backpressure, QUIC pacing/FEC/MTU/congestion, bandwidth adaptation,
WebRTC media/data channels and local-cursor prediction. A transport or codec
replacement needs matched measurements; local cursor prediction does not remove
remote game-response delay. H.264 header rewriting is already present in the Host
for encoders needing VUI injection; actual bitstream/decoder evidence should guide
further changes rather than blindly changing codec declarations or flushing each
frame.

References:
- [Chrome input alignment](https://developer.chrome.com/blog/aligning-input-events)
- [MDN raw pointer events](https://developer.mozilla.org/en-US/docs/Web/API/Element/pointerrawupdate_event)
- [Low-latency canvas](https://developer.chrome.com/blog/desynchronized)
- [WebCodecs specification](https://www.w3.org/TR/webcodecs/)
- [H.264 decoder buffering discussion](https://github.com/w3c/webcodecs/issues/732)
- [WebTransport specification](https://www.w3.org/TR/webtransport/)
- [quic-go datagrams](https://quic-go.net/docs/quic/datagrams/)
- [Centricular's2026 WebTransport analysis](https://centricular.com/devlog/2026-09/webtransport-demo/)
- [WebRTC jitter-buffer target](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpReceiver/jitterBufferTarget)
