Skip to content

Latest commit

 

History

History
263 lines (212 loc) · 18.6 KB

IMAGE_STREAMS.md

File metadata and controls

263 lines (212 loc) · 18.6 KB

Sending images to the page

A host that produces images (a camera, a renderer, a CUDA computation) has several ways to put them on a canvas. This page records the measurements of #769, the track selected from them and how to run both again.

What to use

Send JPEG frames over the bridge, let the page ask for the next one only once it has drawn the previous one, and keep typed-array pixels as the fallback. The runnable example is examples/image-stream/:

cmake --build build --target WebFrontImageStream --parallel 2
build/examples/WebFrontImageStream          # JPEG when the build found libjpeg
build/examples/WebFrontImageStream --raw    # the typed-array fallback
  • The page calls image.next(after, jpeg) and receives the newest image after after. What it has no time for is skipped, so latency does not grow when the page or the network is slow. No WebFront.js, wire format or core change.
  • JPEG is encoded with libjpeg, searched by default on Linux only (-DWEBFRONT_IMAGE_STREAM_JPEG=ON elsewhere, with a libjpeg of your toolchain). Without it, or when the page cannot decode, the pixels are sent as they are.
  • Which format is faster depends on the engine and the machine. Under WebKitGTK, CEF and WebView2, JPEG had the lower latency; on the hosted macOS runner, where WKWebView decoded a JPEG slowly, raw pixels had the lower latency and the higher maximum rate, and delivered more images at 1920 x 1080, though fewer at 960 x 720 and 30 images a second in the last run (see below). Measure on your target; --raw is one option away.

The example asks for one image at a time. The benchmark keeps two in flight, so its throughput figures are higher than the example's would be; its latencies at 30 images a second are the relevant comparison.

What was measured

Pacing of the source. The source ticks every 1/30 s. When preparing a frame takes longer than the period, the ticks that went by are counted as skipped and the next frame waits for the first tick in the future, with no burst afterwards (test/web/ImageStreamPacing.hpp, tested by ImageStreamPacingTests). The first Jetson run, the PC figures (WebKitGTK and CEF) and the first WebView2 and WKWebView runs were recorded with an earlier pacing that advanced the tick once per frame, so a slow frame could be followed by a burst and its missed ticks were not counted. The Jetson, WebView2 and WKWebView tables below were recorded again with the current pacing; the PC tables were not (their frames take 2 and 6 ms to prepare against a 33 ms period, so they are not expected to change, but that was not checked).

image_stream_bench (test/web/ImageStreamBenchmark.cpp) runs the same page in the engine of the browser tests. The host holds 16 synthetic RGBA frames (gradients, a moving checkerboard, three bits of noise in every channel) and sends them by one track; the page draws each frame, reads one pixel back, and acknowledges it. At most two frames are unacknowledged. Latency is read on the host's clock from the start of a frame's preparation (JPEG encoding included) to the reception of its acknowledgement, so it includes the way back of a small message. CPU is in cores: the host process, and the engine's own processes (Linux and Windows). Each case runs 5 s after 1 s of warm-up, at 30 images a second and as fast as the acknowledgements allow.

Track Host to page
raw-bridge RGBA as a typed array, one bridge call per frame
raw-route RGBA in one long response of an addRoute route, read with fetch
jpeg-bridge JPEG quality 0.85 (libjpeg), bridge call, createImageBitmap
jpeg-route the same JPEG through the route
raw-shared WebKitGTK only, prototype: POSIX shared memory read by a web process extension, one copy in the web process

Configuration: AMD Ryzen 9 3900X (24 threads), Ubuntu 26.04, GCC 16.1 Release, Xvfb (no GPU acceleration to rely on), WebKitGTK 2.52.6 and CEF (Chromium 156), 2026-12-06, one run each. The machine was not idle (load average about 15 from other builds): compare the tracks of one table, and read small differences as noise.

WebKitGTK

Latency is the median / 95th percentile in milliseconds; CPU is host + engine.

Track 960x720 at 30 fps: latency, CPU 960x720 max fps 1920x1080 at 30 fps: fps, latency, CPU 1920x1080 max fps
raw-bridge 15.6 / 18.5, 0.68 + 0.58 97 29.9, 50.8 / 54.5, 0.81 + 1.41 40
raw-route 17.3 / 39.1, 1.01 + 1.53 59 21.3, 65.8 / 110, 1.29 + 3.05 22
jpeg-bridge 8.1 / 10.5, 0.72 + 0.31 190 30.1, 17.3 / 20.5, 0.82 + 0.49 75
jpeg-route 40.7 / 44.0, 0.64 + 0.31 stalled 30.1, 49.3 / 52.5, 0.82 + 0.53 55
raw-shared 2.9 / 4.8, 0.70 + 0.15 443 30.1, 6.0 / 8.6, 0.69 + 0.22 145

CEF

Track 960x720 at 30 fps: latency, CPU 960x720 max fps 1920x1080 at 30 fps: fps, latency, CPU 1920x1080 max fps
raw-bridge 8.1 / 11.3, 0.06 + 0.31 123 29.9, 21.6 / 26.1, 0.13 + 0.83 42
raw-route 12.0 / 18.7, 0.33 + 0.73 89 26.7, 53.9 / 80.2, 0.98 + 1.97 23
jpeg-bridge 5.5 / 6.7, 0.09 + 0.13 286 30.1, 18.7 / 23.9, 0.23 + 0.37 87
jpeg-route 6.0 / 7.1, 0.09 + 0.14 265 30.1, 18.5 / 22.9, 0.27 + 0.40 92

The WebKitGTK host figures are higher than the CEF ones for the same host work; the cause was not looked for.

A JPEG frame is about 81 KB at 960 x 720 and 238 KB at 1920 x 1080 (raw: 2.8 MB and 8.3 MB). libjpeg took about 2 ms and 6 ms per frame; drawing it took the page 3 to 5 ms and 10 to 12 ms.

WebView2 and WKWebView (hosted runners)

Recorded on 2026-12-06 by the image_streams dispatch of BuildAndTest.yml at the commit that fixed the pacing (the figures of the first, earlier run were replaced), Release builds, one run each, on GitHub's hosted virtual machines: windows-2025 (4 logical processors reported to the page, Edge WebView2 158) and macos-26 (3 reported, system WKWebView). Their GPU and the load of their physical hosts are unknown, so do not compare these figures with the tables above. Neither host had a JPEG library: the page encoded the JPEG frames once, beforehand, so the latencies contain no encoding time and are not comparable with the JPEG latencies above either. There is no shared memory track, and on macOS the engine's CPU is not measured. Latency is the median / 95th percentile in milliseconds; CPU is host + engine (host only on macOS).

Track, WebView2 960x720 at 30 fps: fps, latency, CPU 960x720 max fps 1920x1080 at 30 fps: fps, latency, CPU 1920x1080 max fps
raw-bridge 30.0, 6.2 / 10.7, 0.03 + 0.29 140 30.0, 17.5 / 21.9, 0.06 + 0.69 53.5
raw-route 30.0, 20.1 / 21.2, 0.66 + 1.10 50.4 17.2, 102 / 116, 1.14 + 1.77 17.2
jpeg-bridge 30.2, 3.3 / 3.5, 0.01 + 0.15 352 30.0, 7.9 / 8.3, 0.01 + 0.32 136
jpeg-route 30.2, 3.6 / 3.8, 0.02 + 0.15 346 30.0, 8.7 / 9.1, 0.06 + 0.35 133
Track, WKWebView 960x720 at 30 fps: fps, latency, CPU 960x720 max fps 1920x1080 at 30 fps: fps, latency, CPU 1920x1080 max fps
raw-bridge 19.4, 12.6 / 49.5, 0.06 86.0 29.2, 26.6 / 38.5, 0.12 45.6
raw-route 7.8, 44.6 / 120, 0.14 34.8 14.2, 134 / 161, 0.61 12.8
jpeg-bridge 24.6, 17.9 / 31.5, 0.03 52.0 22.6, 81.3 / 112, 0.04 21.0
jpeg-route 22.6, 53.9 / 111, 0.06 45.8 0.8, 93.5 / 96.1, 0.01 20.6

The two hosted runs differ from the first ones that were recorded (before the pacing change) by more than a change of pacing explains: on WKWebView, raw-bridge at 960 x 720 and 30 images a second went from 28.0 to 19.4 fps and jpeg-route at 1920 x 1080 from 24.6 to 0.8 fps, a stall like the one of the unpaced 960 x 720 JPEG route under WebKitGTK; on WebView2 the latencies moved by a millisecond or two and raw-route at 1920 x 1080 and 30 images a second went from 30.0 to 17.2 fps. Read the hosted figures as orders of magnitude.

The JPEG frames each engine encoded at "quality 0.85" differ in size: 53 KB and 153 KB under WebView2, 155 KB and 461 KB under WKWebView. Drawing one took 2.8 ms and 7 ms under WebView2, 17 ms and 42 to 46 ms under WKWebView.

WebCodecs, same method as below (median / 95th percentile):

Codec WebView2 960x720 WebView2 1920x1080 WKWebView 960x720 WKWebView 1920x1080
VP8 2.5 / 3.0 ms 8.0 / 9.3 ms 43 / 55 ms 49 / 64 ms
VP9 3.4 / 4.2 ms 8.6 / 9.8 ms 40 / 62 ms 50 / 79 ms
H.264 baseline (Annex B) 3.0 / 3.9 ms 7.1 / 8.4 ms 33 / 51 ms 44 / 73 ms

Jetson Orin Nano

Recorded on 2026-12-06 by two maintainer dispatches of the hardware validation (WebKitGTK, 6 cores, aarch64, JPEG encoded on the host with libjpeg, shared memory track present). The table is the second run, made with the current pacing; the first run, made with the earlier one, is compared below. The runner is deliberately throttled (JETSON_RUNNER): nice 15, idle I/O priority and a service limit of 1.5 cores, so the host CPU column cannot exceed about 1.5 and every figure is that of a board that shares its time. The load of the board besides the job is unknown. The figures are not comparable with the PC's.

Track 960x720 at 30 fps: fps, latency, CPU 960x720 max fps 1920x1080 at 30 fps: fps, latency, CPU 1920x1080 max fps
raw-bridge 18.0, 90.2 / 109, 0.95 + 0.49 23.4 11.8, 151 / 194, 0.70 + 0.76 12.6
raw-route 9.8, 183 / 257, 0.75 + 0.71 10.0 4.9, 379 / 469, 0.50 + 0.96 5.0
jpeg-bridge 17.4, 60.2 / 87.6, 1.14 + 0.31 22.8 13.2, 98.6 / 173, 1.03 + 0.40 16.0
jpeg-route 14.2, 111 / 181, 1.13 + 0.31 18.0 9.8, 189 / 248, 1.06 + 0.41 11.0
raw-shared 21.0, 9.7 / 75.6, 1.24 + 0.20 58.9 24.9, 16.8 / 72.2, 1.12 + 0.32 35.3

libjpeg took 12 to 19 ms per frame at 960 x 720 and 31 to 38 ms at 1920 x 1080, on one thread: at 1080p the encoding alone is the whole frame period or more, and the missed ticks show in the skipped column (16 a second for jpeg-bridge). Drawing a JPEG took the page 22 to 42 ms and 45 to 54 ms. Frames were about the same size as on the PC (81 KB and 238 KB). The WebCodecs test failed for VP8, VP9 and H.264 at both sizes (EncodingError: Decode error): no decoding figure for the board.

Spread. The two runs were separated by the pacing change, so they are not a pure repeat, but they show how far one figure can be trusted. At the maximum rate, where no source tick applies, the fps moved by 0 to 12 % (raw-bridge 960 x 720 21.8 and 23.4, jpeg-bridge 1080p 15.4 and 16.0, raw-shared 960 x 720 56.3 and 58.9, raw-shared 1080p 36.0 and 35.3, jpeg-route 1080p 11.1 and 11.0). At 30 images a second the fps moved more, by up to 23 %: raw-shared 960 x 720 27.4 then 21.0, jpeg-bridge 960 x 720 21.0 then 17.4, jpeg-bridge 1080p 15.6 then 13.2, raw-bridge 960 x 720 19.4 then 18.0; the host's encoding time itself varied from 10 to 19 ms between the runs for the same 960 x 720 case. Latency medians moved by up to 30 % (raw-bridge 960 x 720 69 then 90 ms, jpeg-bridge 960 x 720 70 then 60 ms). Treat a difference smaller than about 25 % between two cells as noise, and the order of tracks, not a figure, as the result.

What the board does to the conclusions (both runs agree on each):

  • Holds: the streamed route is the worst track everywhere (4.9 to 10 fps raw, 9.8 to 14 fps JPEG at 30 images a second), and shared memory the best by a wide margin (latency 10 to 17 ms where the others take 60 to 380 ms, and 35 to 59 fps at the maximum rate). JPEG over the bridge is the better of the two portable tracks at 1920 x 1080: 13.2 fps and 99 ms where raw reaches 11.8 fps and 151 ms (15.6 and 11.2 fps in the first run), and about equal in throughput at the maximum rate (16.0 against 12.6).
  • Differs: at 960 x 720 JPEG and raw pixels have the same frame rate here (17.4 and 18.0 fps at 30 images a second, 22.8 and 23.4 at the maximum), JPEG with the lower latency (60 against 90 ms) because the host encoding and the page decoding cost what the transfer saves. Neither portable track holds 30 images a second on the board, even at 960 x 720, within the CPU limit of this runner; an unthrottled board was not measured. A host that needs 30 images a second at 1080p on this class of hardware needs more than a single libjpeg thread.
  • The host used about one core in every case, up against the runner's limit, which may bound the figures; they say how the board behaves under this limit, not what its hardware can do.

Encoding on the host

test/web/image-stream/host-encoders.sh times ffmpeg 8.0.1 on the same frames (160 per size, RGBA input, conversion included), wall / CPU milliseconds per frame and bytes per frame:

Encoder 960x720 1920x1080
mjpeg -q:v 4 2.1 / 8.5, 32 KB 4.1 / 25, 93 KB
libx264 ultrafast zerolatency 2.7 / 12, 8 KB 6.6 / 37, 16 KB
libvpx (VP8) realtime 26 / 256, 17 KB 36 / 368, 26 KB
libvpx-vp9 realtime 13 / 44, 16 KB 23 / 107, 18 KB
h264_vaapi (AMD GPU) 1.9 / 6.7, 4 KB 4.0 / 18, 8 KB
h264_nvenc, h264_v4l2m2m unavailable on this machine unavailable

The encoders were not tuned to one quality, so sizes are not a comparison of compression. NVENC was not measured: this machine has no NVIDIA GPU, and NVIDIA lists the Jetson Orin Nano without a hardware video encoder. On the Jetson runner the probe found /dev/dri/renderD128, /dev/dri/renderD129 and /dev/nvidia0, no nvv4l2h264enc GStreamer element, and no ffmpeg, so no encoder was timed there: NVENC, and any host video encoder on the board, stay unmeasured. Install ffmpeg or a GStreamer NVIDIA plugin set on the runner to change that.

Decoding with WebCodecs

The page encodes 90 frames with the engine's VideoEncoder, then times each from decode() to the drawn output of the same timestamp, one at a time (median / 95th percentile); a frame not given within 250 ms is counted as held back and not timed. The content differs from the frames above.

The WebKitGTK and CEF figures here were recorded before the page matched outputs by timestamp. They are not affected: a wrong match needed a held-back frame first, and every codec that decoded gave all 90 outputs in time, with none held back. The WebView2 and WKWebView figures above were recorded with the matching.

Codec WebKitGTK 960x720 WebKitGTK 1920x1080 CEF 960x720 CEF 1920x1080
VP8 5 / 7 ms 10 / 14 ms 4.2 / 5.4 ms 10.3 / 13.2 ms
VP9 5 / 7 ms 11 / 14 ms 5.0 / 6.8 ms 10.8 / 13.7 ms
H.264 baseline (Annex B) EncodingError: Decode error same decoding not supported decoding not supported

Why the other tracks were not selected

  • WebCodecs. Decoding a frame costs about what decoding a JPEG does, or more (WKWebView on the hosted runner). What it saves is bandwidth, which the loopback does not lack. It needs a video encoder in the host: the software VP8 and VP9 timings above are close to or beyond the frame period at 1920 x 1080, and H.264, the codec with fast and hardware encoders, decodes under WebView2 and WKWebView but not under WebKitGTK (which accepts the configuration and then fails on the stream its own encoder produced; whether another H.264 stream decodes was not tried) nor the CEF build. Reconsider it for a remote browser on a narrow link.
  • Streamed route. It depends on the engine. Under WebView2 and CEF its JPEG figures equal the bridge's. Under WKWebView it fell behind (23 and 0.8 images a second at 30 asked for JPEG, the second being a stall, and 8 and 14 for raw; in the first hosted run 17 and 25 for JPEG). In WebKitGTK, at 30 images a second, a frame arrived about one frame period later than over the bridge, as if the end of each frame were held until more data came, and the unpaced 960 x 720 JPEG case stalled. Both WebKit engines being affected points to WebKit's side of the exchange; the cause was not identified. Raw frames were slower than over the bridge in all four engines (the server sends a route's body in chunks of 8 KiB, each read on a worker thread, which may explain it). One viewer also holds one of the 4 route worker threads for as long as it watches (HTTP_ASSETS).
  • Shared memory. By far the fastest, and the only track that holds 1920 x 1080 raw frames comfortably. It is not selected: it was prototyped for one embedded engine only, needs a native web process extension in the page's process, needs WebKitGTK's sandbox disabled (the development mode), offers nothing to a browser on another machine, and the prototype filters neither origin nor frame as ADR-017 requires. ADR-017 is therefore unchanged. A zero-copy variant was tried and fails: giving the page an ArrayBuffer over the mapping (jsc_value_new_array_buffer) kills the web process with Disabling Primitive gigacage is forbidden. WebView2's shared buffers (measured at small sizes in ADR-017) were not tried with images; WKWebView has no public shared memory API; CEF was not prototyped.

Not measured

  • Video encoders on the Jetson (see above), WebCodecs decoding on the Jetson, and the board without the runner's CPU limit.
  • Host-side JPEG encoding on Windows and macOS (the page encoded there), and the engine's CPU on macOS.
  • A GPU-accelerated display, a physical screen, a browser on another machine.

Running it again

On the Jetson, the full hardware validation builds for over an hour; to measure alone (about ten minutes once built), dispatch a trusted branch with both inputs:

gh workflow run BuildAndTest.yml --ref <trusted-branch> -f jetson_orin=true -f jetson_orin_measure_only=true

The figures are the image stream bench:, IMAGE-STREAMS and ENCODER lines of the job log. The same workflow records the other engines with -f image_streams=true. On a workstation:

cmake -S . -B build-bench -DCMAKE_BUILD_TYPE=Release -DWEBFRONT_ENABLE_TESTING=ON -DWEBFRONT_EMBED_CEF=OFF \
  -DWEBFRONT_EMBED_WEBKITGTK=ON -DWEBFRONT_WEBTEST_FRONTEND=WebKitGTK
cmake --build build-bench --target image_stream_report --parallel   # under xvfb-run without a display
test/web/image-stream/host-encoders.sh build-bench/test/web/image_stream_bench "$(mktemp -d)"

The report is build-bench/image-streams.json. For CEF, configure with -DWEBFRONT_EMBED_CEF=ON instead of the two WebKitGTK options. The benchmark is never part of the default build or of CTest; the example is checked in a real engine by the ImageStreamExample-jpeg and ImageStreamExample-raw cases.