Mozilla gives WebAssembly a parallelism boost

25.04.2016
Mozilla is improving compilation in both the WebAssembly portable bytecode format and asm.js JavaScript subset by leveraging parallelization in its Firefox browser.

Using parallelism, an engineer at Mozilla worked on reducing startup times in asm.js programs in the browser. "As our JavaScript engine, SpiderMonkey, uses the same compilation pipeline for both asm.js and WebAssembly, this also benefitted WebAssembly compilation," said the engineer, Benjamin Bouvier.

Parallelization, he said, consists of splitting a sequential program into smaller independent tasks, then running them on different CPUs. "If your program is using N cores, it can be up to N times faster."

Mozilla's goal is to make more work run in parallel by taking out the SpiderMonkey middle-level intermediate representation (MIR) from the main thread, as well as removing and code generation. "Instead of emitting a MIR graph as we parse the function's body, we emit a small, compact, pre-order representation of the function's body," Bouvier said. "In short, a new IR. As work was starting on WebAssembly (wasm) at this time, and since asm.js semantics and wasm semantics mostly match, the IR could just be the wasm encoding, consisting of the wasm opcodes plus a few specific asm.js ones. Then, wasm is translated to MIR in another thread." Instead of parsing and generating MIR in a single pass, wasm IR would be parsed and generated in one pass, while the MIR would be generated out of the wasm IR in another pass.

While Mozilla found compilation much faster in its new scheme, it still can be a pain, especially in mobile applications, according to Bouvier. "This is mostly due to the fact that we're running a whole multi-million-line codebase through the back end of a compiler to generate optimized code," he said. "Following this work, the next bottleneck during the compilation process is parsing, which matters for asm.js in particular, which source is plain text. Decoding WebAssembly is an order of magnitude faster though, and it can be made even faster." More load-time optimizations are coming, Bouvier said.

WebAssembly is a highly touted attempt to improve the Web's performance through a portable code format running in browsers at native speeds. It has been supported by browser vendors Mozilla, Google, Microsoft, and Apple.

(www.infoworld.com)

Paul Krill

Zur Startseite