Browser-side ML inference means the model runs inside the user’s browser, on their own CPU or GPU, instead of on a server the application calls over the network. WebAssembly and native C++ are not two implementations of the same decision. WebAssembly is a distribution and isolation choice that comes with a performance ceiling, and native C++ (or CUDA behind a service call) is a performance choice that comes with a distribution cost. An honest comparison measures the same profiled bottleneck under both targets, checks that SIMD and threads are really switched on in the WASM build, and treats a single browser’s number as one point in a range, not as the ceiling. Whether a port earns its cost at all is covered in our port decision overview. This article stays on the browser branch of that decision.
When the Browser Is a Constraint, Not a Performance Choice
Some deployment constraints force inference into the browser regardless of speed. The web.dev guidance from Google puts the trade plainly: client-side AI keeps data on the user’s device and removes network latency, but it needs highly specific, well-defined use cases to perform well.
The constraints that make the browser necessary are concrete:
- Universal access. The browser is universally accessible and abstracts away the backends of different device vendors, which is why the WebLLM authors (2024) treat it as a natural on-device platform.
- Data must stay on the device. The W3C WebNN specification describes in-browser inference as a privacy improvement over cloud inference because images, audio, video and other personal inputs never leave the user’s device.
- Offline operation and serving cost. The ONNX Runtime Web documentation lists offline inference and reduced cloud serving costs among the reasons to run in the browser.
The same sandbox also takes tools away. The nnJIT authors (MobiSys 2024) point out that the browser sandbox, which isolates web content from the underlying system, also restricts use of sophisticated native DNN inference libraries such as Eigen for CPU and cuBLAS for GPU. If none of the constraints above applies to you, the browser is a choice, and it has to win on measured latency and cost against a server path.
Browser-Side ML Inference Runtimes and What Each One Limits
In ONNX Runtime Web, WASM supports every ONNX operator, while WebGL, WebGPU and WebNN support only a subset. WebAssembly is the CPU path, compiled from C or C++ and executed by the browser’s virtual machine. Our explainer on how WebAssembly works for ML inference covers the execution model, so this section sticks to the limits that shape a comparison.
| Runtime | Runs on | Main limit for inference |
|---|---|---|
| WebAssembly (with SIMD and threads) | CPU | 4GiB addressable memory under 32-bit addressing; SIMD fixed at 128-bit width; threads need cross-origin isolation |
| WebGL | GPU (through graphics shaders) | No work groups or shared memory; the TensorFlow.js team (2019) measured a 3-10x gap to CUDA |
| WebGPU | GPU (compute shaders) | Per-dispatch validation overhead that compounds across many small operations; partial operator coverage in ONNX Runtime Web |
| WebNN | CPU, GPU or NPU, chosen by the platform | Available only in secure contexts |
WebAssembly: Memory, SIMD and Threads
WebAssembly memory comes in 64KiB pages, and 2^16 pages, or 4GiB, is the most a module can address with 32-bit addressing. The ONNX Runtime Web documentation is explicit about the consequence: it currently has no way to run models larger than 4GB. A second ceiling sits below the first. Chrome limits a single ArrayBuffer to about 2GB, which ONNX Runtime Web works around by allocating through WebAssembly.Memory(), at the cost of losing transferability and the Proxy feature.
The WebAssembly SIMD proposal standardises fixed-width 128-bit operations only, while x86 CPUs with AVX-512 offer 512-bit instructions. Our article on SSE vs AVX and what SIMD width buys a ported inference path works through what that width difference costs. SIMD has been on by default since Chrome 91 and Firefox 89, according to the V8 team.
A WASM build loses its threads silently when one deployment header is missing. Browsers expose SharedArrayBuffer only under cross-origin isolation, which means serving Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp. Without those headers, ONNX Runtime Web falls back to single-threaded WASM, which SitePoint’s backend benchmark puts at 3 to 4x slower for larger models, and inference still works, so nothing visibly breaks. Threading support also varies by platform: when the TensorFlow team wrote in September 2020, multi-threaded WASM was still in progress on mobile browsers and SIMD on iOS was still under development.
WebGL, WebGPU and WebNN
WebGL is the old GPU route, and its precision is set by the hardware. The TensorFlow.js documentation warns that mobile devices may support only 16-bit float textures, while WASM keeps 32-bit float arithmetic consistent across devices. WebGPU is the successor. web.dev reports it as officially supported across Chrome, Edge, Firefox and Safari, which is a real change from 2019, when the Ma et al. study found it only in Safari Technology Preview. WebNN abstracts across CPU, GPU and dedicated ML accelerators, and lets the browser pick the device combination.
How Big Is the Gap Between Browser-Side ML Inference and Native C++?
The answer depends heavily on which browser path is measured, so treat any single “near-native” figure with suspicion.
Start with general-purpose code. The 2019 “Not So Fast” study ran SPEC CPU benchmarks compiled to WebAssembly in Chrome and Firefox and found a mean slowdown against native of 1.55x in Chrome and 1.45x in Firefox, with peaks of 2.5x and 2.08x. Seven of the 15 benchmarks finished within 1.5x of native in each browser. That is larger than the original WebAssembly paper reported, where seven of 24 benchmarks ran within 10% of native, as the same study notes.
The study also measured the causes with performance counters:
- WebAssembly code retired about twice as many loads and stores as native code, which the authors attribute to fewer available registers, a weaker register allocator and poor use of x86 addressing modes.
- Its dynamic safety checks added branches, roughly 1.6-1.75x more.
- The extra generated instructions caused 2.83x (Chrome) and 2.04x (Firefox) more L1 instruction-cache misses.
The authors separate implementation weaknesses, such as register allocation and code generation, which better online compilers could narrow, from design costs such as stack-overflow checks, indirect-call checks and reserved registers, which WebAssembly’s safety guarantees require. For inference the dated part matters too. Their matrix-multiply kernel ran 2-3.4x slower than native with vectorisation disabled, because WebAssembly had no vector instructions at the time, and SIMD has shipped since then.
Inference-specific studies report very different gaps. Wang et al. (TOSEM, 2024) tested nine models across browsers on 50 PC and 20 mobile devices and found in-browser inference averaging 16.9x slower than native on PC CPU and 4.9x slower on PC GPU. Ma et al. (WWW 2019) found TensorFlow.js within 1-2x of native TensorFlow in Python on a discrete GPU for models like MobileNet and Inception. The WebLLM authors (2024) report retaining up to 80% of native performance on the same device. A 2026 study characterising WebGPU dispatch overhead across GPU vendors and browsers measured Chrome on Metal reaching 97% of native MPS float16 decode throughput with WebLLM.
They measured different stacks. Ma et al. identify the backend as the most important factor in the gap, and the WebLLM figures come from compiler-optimised WebGPU kernels. The Wang et al. dataset is the broadest on devices, so we would treat it as the better guide to what in-browser inference delivers across a real user base, and the WebLLM figure as what focused kernel work can recover. Memory deserves the same attention as latency: Wang et al. saw in-browser inference use at times more than 334.6 times the model’s own size.
A Fair Measurement Procedure Across Browsers and Devices
The comparison is only defensible if both sides measure the same profiled bottleneck. For profiling the Python path before any of this, see how to profile a Python inference path before committing to a port.
TechnoLynx runs this comparison as the browser-target branch of the port-decision step in the Inference Cost-Cut Pack engagement, profiling your current inference path and measuring that baseline against WASM and native C++ candidates before any engineering is committed.
- Fix the bottleneck first. Profile the current path and pick the operator or stage that dominates. “Vendor APIs are faster” and “avoid branches” only make sense in context, and that context comes from profiling, not from reading blog posts.
- Match numeric precision on both sides. In the 2026 WebGPU study, comparing float32 WebGPU against float16 CUDA inflated the gap: at matched float32 it narrowed from 8.8x to 1.4x.
- Separate compilation and cold start from steady state. The “Not So Fast” study timed execution only after JIT compilation had finished. Report first-inference time separately, because WebGPU shader compilation can add 1 to 5 seconds to the first pass.
- Verify the WASM configuration rather than assume it. Record whether SIMD and threads were active for each run, and check the console for SharedArrayBuffer warnings, because a missing isolation header degrades silently.
- Split per-dispatch cost from per-operation overhead on GPU paths. The 2026 study measured the WebGPU API alone at 24-36μs per dispatch on Vulkan, against about 95μs per operation once framework code was included, and argues the distinction decides which optimisation helps.
- Run on the devices your users have. nnJIT’s authors (2024) found one TensorFlow.js kernel ranging from a 2% to a 246% slowdown across devices, and browser choice alone moved WebLLM decode from 46-51 tok/s in Chrome to 9.1-9.6 tok/s in Firefox.
- Record peak memory, not just latency.
tf.profile()reports peak tensors and bytes allocated inside a function, which the TensorFlow.js authors flag as important on memory-limited phones.
The output is a small table per candidate target: per-request latency with SIMD and threads on and off, peak memory, payload size over the wire, first-inference time, and the browsers and devices covered. Anything less leaves the port decision resting on preference.
WASM or WebGPU for a Given Model
Once the browser is settled, WASM versus WebGPU is the next call, and model size, task shape and hardware decide it. WebGPU has to upload inputs to GPU buffers and read results back, and SitePoint’s benchmark explains that this marshalling cost is why small, fast passes lose on the GPU. On an M2 MacBook Air the same write-up measured 8-12ms median for a small embedding model on WASM against 15-25ms on WebGPU. The TensorFlow.js documentation reaches the same conclusion from fixed per-op shader costs: tiny models with many ops, such as the 400KB BlazeFace, can run faster on WASM than WebGL.
| Situation | Lean towards | Why |
|---|---|---|
| Small embedding model, single input under about 128 tokens | WASM | Dispatch overhead exceeds compute on the GPU |
| Cold start is a hard requirement | WASM | No shader compilation step |
| Audience includes older hardware or browsers without WebGPU | WASM | The only broadly viable default |
| INT8-quantised model on CPU | WASM | SIMD operates on packed 8-bit integers; INT8 can run 2-3x faster than FP32 |
| Model above roughly 100M parameters, sustained or batched work, capable GPU | WebGPU | Computation lasts long enough to amortise transfer overhead |
| Operators outside the GPU provider’s coverage | WASM, or test carefully | Unsupported ops fall back to CPU and create a mixed path |
Batch size matters too. At batch size 1, the 2026 WebGPU study found every operation overhead-bound, with crossover to compute-bound behaviour needing batches of 7 to 119 depending on the operation. At batch 1, cutting 312 dispatches with unchanged kernels gave a 53% end-to-end improvement.
When Is a Native C++ or CUDA Service Still Cheaper than the Browser?
A server-side native service stays the better option when the model is too large for client hardware or when you do not want the model downloaded to the device. The 2026 WebGPU study concludes that browser inference is currently practical for latency-tolerant, portability-critical, privacy-sensitive or educational workloads, not for latency-critical or high-throughput serving where CUDA is available. Above 4GB the question is closed for ONNX Runtime Web anyway.
Browser inference shifts compute off your infrastructure, and the nnJIT authors cite Microsoft and Google reports that on-device inference can approach zero serving cost at scale. web.dev, however, scores client-side custom models low on compatibility and developer convenience, because someone has to manage runtimes, optimisation and fallbacks across devices. We would compare cost per request on the server against the fixed engineering and support cost of the browser path. web.dev notes that mature AI systems rarely run on a single platform or with one model, distributing workloads across heterogeneous compute targets to optimise the trade-offs. Which latency and footprint thresholds justify each target is covered in latency and footprint targets that justify a C++, WASM or Rust port.
What Browser-Side Inference Costs After Launch
The run cost moves to the client, but four other costs land on your team.
Download size and caching. Chrome’s developer documentation lists MediaPipe object-detection models from 5.6MB to about 25MB, and a 1.35GB Gemma 2B INT4 model that it calls very small for an LLM. Chrome’s storage team recommends explicit caching through the Cache API rather than relying on the HTTP cache, and ranks IndexedDB worst for large models because of serialisation. Ma et al. (2019) found that loading and warming the model took longer than the inference itself, so preloading belongs in the design from the start.
Cold start. WebGPU shader compilation can be hidden by running a dummy inference during application start-up, before the user asks for a result. WASM avoids that cost but not the download.
Coverage. Plan for fallback paths from the beginning, because availability varies by browser and device. The TensorFlow.js paper’s figure of WebGL running on 52% of Android devices comes from 2018 WebGLStats data and shows how uneven mobile reach can be, though it is too old to use for planning today.
Responsiveness and maintenance. Wang et al. measured a 67.2% increase in GUI render time while in-browser inference ran, and web.dev recommends moving CPU-based WASM inference into a web worker. The nnJIT authors note that in-browser frameworks have needed their handwritten kernels rewritten for each new backend. The longer-term picture is in the ongoing cost of a ported inference path, and the checks before shipping follow the release-readiness decision framework.
Who Can Run a WASM-Versus-Native Comparison on Our Inference Path?
TechnoLynx reports per-request latency and peak memory for each target against the same bottleneck, plus the WASM path’s bundle size, cold-start time and browser and device coverage. Whether to do this in-house depends on whether your team already has a profiling habit and access to the devices your users actually carry. If it does, the procedure above is the work. If you bring in a partner, choose one that reports SIMD and thread state and matched precision with every figure, and that will tell you when the server path wins. Our wider GPU and inference engineering work covers the native side when that is the answer.
This engagement does not fit every case. If your model is above 4GB, ONNX Runtime Web cannot run it, so there is no WASM candidate to compare. If you only need to choose between ONNX Runtime Web execution providers for a model that already runs, the vendor’s own advice is to try different providers and session options and test them.
The Comparison That Decides the Port
A browser number on its own does not set the ceiling. What decides the port is the gap between that number and a native build measured on the same bottleneck, at the same precision, on the devices your users own, set against what the deployment would cost you without the browser. If the browser path loses on latency but is the only route that meets your data-residency or no-install requirement, the useful question becomes how much of the gap focused kernel work can recover, and WebLLM retains up to 80% of native performance. If no requirement forces the browser, take the measurements back to the port decision overview and let the server path compete on cost per request.