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 performancethrough a portable code format running in browsers at native speeds. It has been supported by browser vendors Mozilla, Google, Microsoft, and Apple.
Sign up for CIO Asia eNewsletters.