Tuesday, March 15, 2016

Experimental support for WebAssembly in V8

For a comprehensive overview of WebAssembly and a roadmap for future community collaboration, see A WebAssembly Milestone on the Mozilla Hacks blog.

Since June 2015, collaborators from Google, Mozilla, Microsoft, Apple and the W3C WebAssembly Community Group have been hard at work designing, specifying, and implementing [1][2][3][4] WebAssembly, a new runtime and compilation target for the web. WebAssembly is a low-level, portable bytecode that is designed to be encoded in a compact binary format and executed at near-native speed in a memory-safe sandbox. As an evolution of existing technologies, WebAssembly is tightly integrated with the web platform, as well as faster to download over the network and faster to instantiate than asm.js, a low-level subset of JavaScript.

Starting today, experimental support for WebAssembly is available in V8 and Chromium behind a flag. To try it out in V8, run d8 version 5.1.117 or greater from the command line with the --expose_wasm flag or turn on the Experimental WebAssembly feature under chrome://flags#enable-webassembly in Chrome Canary 51.0.2677.0 or greater. After restarting the browser, a new Wasm object will be available from the JavaScript context which exposes an API that can instantiate and run WebAssembly modules. Thanks to the efforts of collaborators at Mozilla and Microsoft, two compatible implementations of WebAssembly are also running behind a flag in Firefox Nightly and in an internal build of Microsoft Edge (demonstrated in a video screencapture).

The WebAssembly project website has a demo showcasing the runtime’s usage in a 3D game. In browsers that support WebAssembly, the demo page will load and instantiate a wasm module that uses WebGL and other web platform APIs to render an interactive game. In other browsers, the demo page falls back to an asm.js version of the same game.


Under the hood, the WebAssembly implementation in V8 is designed to reuse much of the existing JavaScript virtual machine infrastructure, specifically the TurboFan compiler. A specialized WebAssembly decoder validates modules by checking types, local variable indices, function references, return values, and control flow structure in a single pass. The decoder produces a TurboFan graph which is processed by various optimization passes and finally turned into machine code by the same backend which generates machine code for optimized JavaScript and asm.js. In the next few months, the team will concentrate on improving the startup time of the V8 implementation through compiler tuning, parallelism, and compilation policy improvements.

Two upcoming changes will also significantly improve the developer experience. A standard textual representation of WebAssembly will enable developers to view the source of a WebAssembly binary like any other web script or resource. In addition, the current placeholder Wasm object will be redesigned to provide a more powerful, idiomatic set of methods and properties to instantiate and introspect WebAssembly modules from JavaScript.

The V8 / WebAssembly team looks forward to continued collaboration with other browser vendors and the greater community as we work towards a stable release of the runtime. We’re also planning future WebAssembly features (including multi-threading, dynamic linking, and GC / first-class DOM integration) and continuing the development of toolchains for compiling C, C++, and other languages via the WebAssembly LLVM backend and Emscripten. Check back for more updates as the design and implementation process continues.

Posted by Seth Thompson, WebAssembly Wrangler

V8 Release 5.0

The first step in the V8 release process is a new branch from the git master immediately before Chromium branches for a Chrome Beta milestone (roughly every six weeks). Our newest release branch is V8 5.0, which will remain in beta until we release a stable build in conjunction with Chrome 50 Stable. Here’s a highlight of the new developer-facing features in this version of V8.

Note: The version number 5.0 does not carry semantic significance or mark a major release (as opposed to a minor release).

Improved ECMAScript 2015 (ES6) support

V8 5.0 contains a number of ES2015 features related to regular expression (regex) matching.

RegExp Unicode flag

The RegExp Unicode flag, u, switches on a new Unicode mode for regular expression matching. The Unicode flag treats patterns and regex strings as a series of Unicode codepoints. It also exposes new syntax for Unicode codepoint escapes.
// false

// true

// true

// true

The u flag also makes the . operator (also known as the single character matcher) match any Unicode symbol rather than just the characters in the Basic Multilingual Plane (BMP).
var string = 'the 🅛 train';

// false

// true 

RegExp customization hooks

ES2015 includes hooks for RegExp subclasses to change the semantics of matching. Subclasses can override methods named Symbol.match, Symbol.replace, Symbol.search and Symbol.split in order to change how RegExp subclasses behave with respect to String.prototype.match and similar methods.

Performance improvements in ES2015 and ES5 features

Release 5.0 also brings a few notable performance improvements to already implemented ES2015 and ES5 features.

The implementation of rest parameters is 8-10x faster than that of the previous release, making it more efficient to gather large numbers of arguments into a single array after a function call. Object.keys(), useful for iterating over an object’s enumerable properties in the same order returned by for..in, is now approximately 2x faster.


Please check out our summary of API changes. This document gets regularly updated a few weeks after each major release.

Developers with an active V8 checkout can use 'git checkout -b 5.0 -t branch-heads/5.0' to experiment with the new features in V8 5.0. Alternatively you can subscribe to Chrome's Beta channel and try the new features out yourself soon.

Posted by the V8 team