Monday, October 31, 2016

WebAssembly Browser Preview

Today we’re happy to announce, in tandem with Firefox and Edge, a WebAssembly Browser Preview. WebAssembly or wasm is a new runtime and compilation target for the web, designed by collaborators from Google, Mozilla, Microsoft, Apple, and the W3C WebAssembly Community Group.

What does this milestone mark?

This milestone is significant because it marks:
  • a release candidate for our MVP (minimum viable product) design (including semantics, binary format, and JS API)
  • compatible and stable implementations of WebAssembly behind a flag on trunk in V8 and SpiderMonkey, in development builds of Chakra, and in progress in JavaScriptCore
  • a working toolchain for developers to compile WebAssembly modules from C/C++ source files
  • a roadmap to ship WebAssembly on-by-default barring changes based on community feedback 
You can read more about WebAssembly on the project site as well as follow our developers guide to test out WebAssembly compilation from C & C++ using Emscripten. The binary format and JS API documents outline the binary encoding of WebAssembly and the mechanism to instantiate WebAssembly modules in the browser, respectively. Here’s a quick sample to show what wasm looks like:

Raw Bytes
Text Format
C Source
02 40
03 40
20 00
45
0d 01
block
 loop
   get_local 0
   i32.eqz
   br_if 1
while (x != 0) {

20 00
21 02
   get_local 0
   set_local 2
 
 z = x;
20 01
20 00
6f
21 00
   get_local 1
   get_local 0
   i32.rem_s
   set_local 0
 

 
 x = y % x;
20 02
21 01
   get_local 2
   set_local 1

 y = z;
0c 00
0b
0b
   br 0
 end  
end


}
20 01
get_local 1
return y;

Greatest Common Divisor function

Since WebAssembly is still behind a flag in Chrome (chrome://flags/#enable-webassembly), it is not yet recommended for production use. However, the Browser Preview period marks a time during which we are actively collecting feedback on the design and implementation of the spec. Developers are encouraged to test out compiling and porting applications and running them in the browser.

V8 continues to optimize the implementation of WebAssembly in the TurboFan compiler. Since last March when we first announced experimental support, we’ve added support for parallel compilation. In addition, we’re nearing completion of an alternate asm.js pipeline, which converts asm.js to WebAssembly under the hood so that existing asm.js sites can reap some of the benefits of WebAssembly ahead-of-time compilation.

What's next?

Barring major design changes arising from community feedback, the WebAssembly Community Group plans to produce an official specification in Q1 2017, at which point browsers will be encouraged to ship WebAssembly on-by-default. From that point forward, the binary format will be reset to version 1 and WebAssembly will be versionless, feature-tested, and backwards-compatible. A more detailed roadmap can be found on the WebAssembly project site.

20 comments:

  1. Webassembly is a game changer for performance on the web, hopefully it will see new languages and workflows that will let developers from all backgrounds contribute. Exciting times and great job.

    ReplyDelete
  2. IT'S HAPPENING!

    Believe you or not, starting today, web is getting much less laggy!

    ReplyDelete
  3. I am really excited to see the standard being adopted. Any word on Safari support?

    ReplyDelete
  4. They said it's in progress in JavaScriptCore (which is what safari uses)

    ReplyDelete
  5. WoW!!! This can save the whole web from the eternal pain in future! (a.k.: JavaScript)

    All you guys are true heros!

    PS.: I know. JavaScript don't will die in soon, but is really awesome dream with a real alternative.

    ReplyDelete
    Replies
    1. Maybe you should learn something about modern javascript before bashing it like that.
      Just saying.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Lol Halvard. Modern JS, even with ES6 and strongly typed langs getting traction, is a nightmare compared to using a REAL programming language like Python or Java/Scala. So before you assume someone's experience level (because I doubt Manoel would comment without having used JS), take your JS apologist attitude elsewhere and prepare to embrace our new Web Assembly overlords.

      Delete
    4. This comment has been removed by the author.

      Delete
    5. @halojedi, how do you term a language as REAL and UNREAL (being teh opposite of REAL?)

      Delete
    6. doesn't matter, I'm writing unreal software everyday!

      Delete
    7. This comment has been removed by the author.

      Delete
    8. JavaScript is a scriptting language (it's in the job description!) which has grown (like a Frankenstein) into a programming language because of the absurdly fast web growth.

      Modern JS (by modern I mean TypeScript with ES7 features like async/await) is the state-of-the-art in the JS world, but it's not possible to run it directly in the browser nowadays (and won't in the close future).

      Being able to run C programs (with already written C libs), or Swift 3 state-of-the-art code directly into the browser, **without** the specific support from every major browser company is just FU**ING AWESOME!

      Delete
    9. "I know. JavaScript don't will die in soon, but is really awesome dream with a real alternative."

      Nice engrish.

      Yes, JavaScript, a highly expressive yet misunderstood programming language, won't die anytime soon, probably never. But you will.

      Delete
  6. This comment has been removed by the author.

    ReplyDelete
  7. I'm extremely happy for this and for those who are crapping on Javascript, you most probably suck at it big time and that's the main reason for it. Anyway, can't wait to write some C based languages for the web. Cheers

    ReplyDelete