Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Mozilla Hacks 9 min read Case study mediumAdept

Neural Machine Translation Engine for Firefox Translations add-on

Firefox Translations runs neural machine translation entirely on the client by compiling the Bergamot Translator engine, a C++ layer on the Marian framework, to WebAssembly. Wasm won over native Firefox integration and native messaging because it was safer, cross-platform and could be shipped as a single binary. The first prototype was unusable: about 8 seconds to start, 95 words per second and a ~250 MB binary. Loading models as byte buffers instead of bundling them, swapping hot try/catch paths for if/else, and adding experimental, non-standard and native GEMM intrinsics in Firefox brought this to ~1 second startup, ~870 wps for English to German and a ~4.94 MB binary. ARM performance and multithreading still depend on standardized Wasm GEMM and SharedArrayBuffer.

Related posts

  • Training efficient neural network models for Firefox Translations

    Mozilla Hacks mediumAdept

    Firefox Translations runs neural machine translation locally on CPU using small models produced by an open-source, reproducible training pipeline from the Bergamot project. The pipeline cleans parallel corpora from OPUS, WMT and Paracrawl with heuristics and bicleaner, augments the data with back-translation, and trains a large transformer teacher. That teacher is then compressed through ensemble knowledge distillation into a small student model with 8-bit quantization. The resulting en-pt student is 47x smaller (17MB vs 798MB) and 37x faster on one CPU core, losing under 2 BLEU points, and some models match cloud translation APIs. The Marian-based pipeline is orchestrated with Snakemake and distributed across GPU nodes with Slurm, and the models ship in the browser via a WebAssembly build of bergamot-translator.

  • Why is WebAssembly a second-class language on the web?

    Mozilla Hacks mediumAdept

    WebAssembly remains second-class on the web because it can only load code and reach Web APIs through JavaScript. That forces arcane instantiation boilerplate, language-specific glue code from tools like wasm-bindgen and embind, JS-centric documentation, and real runtime overhead. A 2020 TodoMVC experiment with the Dodrio Rust framework found that removing JS glue cut DOM-update time by 45%. The esm-integration proposal, being implemented in Firefox, simplifies loading, and the WebAssembly Component Model with WIT interfaces is proposed as a standardized artifact that could let Wasm call Web APIs directly with no JavaScript in between.

  • Extensible Language Support in Zed - Part 1

    Zed mediumAdept

    Zed loads third-party Tree-sitter grammars as WebAssembly modules using a hybrid design. Native code consumes the parser's static parse tables after they are copied out of wasm linear memory, while only the lexing functions, including hand-written external scanners, run inside Wasmtime. This avoids depending on the user's C compiler and keeps buggy scanners from crashing the editor. It also avoids copying large syntax trees out of wasm memory on every keystroke. A new `WasmStore` API lets wasm-loaded languages behave identically to native ones, and a bundled mini-libc with a bump allocator that is reset each parse makes scanner memory leaks impossible.

  • How We Built the Turso Shell in the Browser

    Turso mediumAdept

    Turso's SQLite-compatible database can run entirely in the browser via WebAssembly, persisting data to OPFS with no backend. The walkthrough builds a SQL shell with Vite, React and TypeScript. It covers importing from the @tursodatabase/database-wasm/vite export to work around a Vite dev-server WASM issue, and setting COOP/COEP headers so SharedArrayBuffer is available. It then builds a query executor that maps prepared-statement results into a table, and upgrades the textarea to a CodeMirror editor with SQL highlighting, autocomplete and a Mod-Enter keybinding.

  • WebAssembly and Back Again: Fine-Grained Sandboxing in Firefox 95

    Mozilla Hacks mediumAdept

    Firefox 95 ships RLBox, a fine-grained sandboxing technique that compiles third-party C/C++ libraries (Graphite, Hunspell, Ogg, with Expat and Woff2 following in 96) to WebAssembly and then back to native code, so untrusted code runs in-process but cannot jump to unexpected code or touch memory outside its region. This avoids the asynchrony refactoring and memory overhead of process-based isolation, needing only sanitization of values crossing the boundary via RLBox's tainting layer. The production pipeline replaced the Cranelift prototype with wasm2c, translating wasm to C and feeding it back into Clang, which preserves PGO, cross-boundary inlining, crash reporting and debugger support. Mozilla now pays bug bounties for sandbox escapes even without a library vulnerability.

The quest for software engineering knowledge.

Look:
Layout: