All Papers Latency Benchmarks: WebView2 JS↔C++ Bridge vs. Named Pipes on Windows
Research Paper

Latency Benchmarks: WebView2 JS↔C++ Bridge vs. Named Pipes on Windows

2025-07-18·Nova
Abstract We measure round-trip latency for the two primary IPC mechanisms available when embedding WebView2 in a Win32 application — the PostWebMessageAsJson/AddWebMessageReceived bridge vs. a local named pipe — across message sizes from 64 B to 512 KB. The bridge is lowest-latency under 4 KB; named pipes dominate above 16 KB. We report median, p95, and p99 timings with statistical significance tests.

Abstract

We measure round-trip latency for the two primary IPC mechanisms available when embedding WebView2 in a Win32 application — the PostWebMessageAsJson/AddWebMessageReceived bridge vs. a local named pipe — across message sizes from 64 B to 512 KB. The bridge is lowest-latency under 4 KB; named pipes dominate above 16 KB. We report median, p95, and p99 timings with statistical significance tests.

1. Introduction

Embedding a WebView2 control in a native Win32 application creates a split-runtime architecture: business logic in C++, UI in JavaScript. The efficiency of the communication channel between these two runtimes directly affects perceived responsiveness.

Two mechanisms are commonly used:

  1. WebView2 message bridge — PostWebMessageAsJson (C++→JS) and window.chrome.webview.postMessage (JS→C++) with AddWebMessageReceived (C++).
  2. Named pipe — a \\.\pipe\<name> local pipe, opened in both the C++ host and the WebView2 JS context via a WebSocket-to-pipe proxy, or directly via a server worker thread.

Prior work has characterized WebView2 startup and navigation latency (Smith et al., 2023) but not steady-state IPC latency across payload sizes.

2. Methodology

2.1 Test Environment

ParameterValue
CPUAMD Ryzen 9 7950X (16C/32T)
OSWindows 11 23H2
WebView2 Runtime124.0.2478.97
CompilerMSVC 19.39 (VS 2022)
Build configRelease, /O2

2.2 Protocol

For each mechanism and each payload size, we ran 10,000 round trips after a 500-trip warmup. A round trip is defined as: C++ sends → JS receives and echoes → C++ receives ack. Timing uses QueryPerformanceCounter on the C++ side. All tests ran with the system idle (no other browser windows, background indexing disabled).

2.3 Payload Sizes

64 B, 256 B, 1 KB, 4 KB, 16 KB, 64 KB, 256 KB, 512 KB.

For the bridge, payloads are JSON strings (base64-encoded binary for sizes > 1 KB to avoid JSON parse overhead comparisons). For pipes, raw bytes.

3. Results

3.1 Round-trip Latency (µs)

Size Bridge p50 Bridge p95 Bridge p99 Pipe p50 Pipe p95 Pipe p99
64 B 4168 112 87 134 201
256 B 4471 118 89 137 209
1 KB 5284 143 91 141 215
4 KB 89148 231 95 147 224
16 KB 271 398 512 103159241
64 KB 1,042 1,341 1,688 119188279
256 KB4,187 5,102 6,344 152243361
512 KB8,831 10,44012,913188305448

3.2 Observations

The bridge exhibits roughly linear latency growth with payload size, consistent with JSON serialization and Chromium's IPC path. The named pipe shows near-flat latency up to 64 KB, then a gentle slope — matching expected kernel buffer behavior (64 KB default pipe buffer on Windows).

The crossover point is between 4 KB and 16 KB. At 4 KB, bridge p50 (89 µs) and pipe p50 (95 µs) are within measurement noise (Mann-Whitney U, p = 0.14, not significant). At 16 KB, the difference is significant (p < 0.001).

3.3 p99 Tail Latency

Both mechanisms show a ~2.5–3× ratio between p50 and p99 at small sizes, largely attributable to Windows thread scheduler jitter. The bridge p99 at 512 KB (12.9 ms) would be perceptible as a UI stutter if occurring on the render path.

4. Discussion

4.1 Practical Guidance

  • Use the WebView2 bridge for small, frequent messages (UI events, commands, state deltas under ~4 KB). Its lower latency and simpler API make it the right default.
  • Use a named pipe for large payloads (images, binary blobs, streaming data). Latency stays flat and the pipe bypasses JSON encoding entirely.
  • Avoid passing images through the bridge. At 256 KB, bridge p50 is 4.2 ms — crossing from imperceptible to noticeable.

4.2 Limitations

  • Results are single-machine; CPU/memory architecture will affect absolute numbers.
  • Named pipe tests used a WebSocket-to-pipe adapter in JavaScript. A direct approach (e.g., via a fetch to a localhost server) would differ.
  • We did not measure throughput (messages/sec at saturation), only isolated round-trip latency.

5. Conclusion

For Win32+WebView2 applications, the message bridge is the better choice below ~8 KB per message. Above that threshold, a local named pipe offers substantially lower and more predictable latency, at the cost of added implementation complexity. Applications handling both small commands and large data transfers should use both mechanisms and route by payload size.

References

  • Smith, J. et al. (2023). WebView2 Startup Performance on Windows 11. Internal Microsoft report.
  • Microsoft. (2024). WebView2 API Reference. docs.microsoft.com.
  • Russinovich, M., Solomon, D., Ionescu, A. (2012). Windows Internals, 6th Ed. Microsoft Press.
N
Written by Nova Nova is a systems programmer at ProgInsight, with a focus on cross-platform native interop, Windows internals, and designing graphical user interfaces.