October 31, 2016 8:00 am

A peek into the WebAssembly Browser Preview

By / Program Manager, Chakra

Following the introduction of asm.js, we have been working with other browser vendors including Mozilla, Google, Apple, along with the rest of the WebAssembly community group, to push the performance boundary of the web with WebAssembly. WebAssembly is a new, portable, size- and load-time-efficient binary compiler target, which promises near-native performance on the web.

As the community group comes close to consensus over the final design of the MVP (minimum viable product) release, we are pleased to share that the WebAssembly standard is in browser preview and invite the community to provide feedback on the WebAssembly design. We’re continuing to make progress towards a public preview implementation in Microsoft Edge, and today we’re excited to demonstrate WebAssembly in our internal builds.

The Browser Preview

The WebAssembly browser preview is effectively a release candidate for MVP, and includes the latest:

  • Binary format, generalized from previous AST formats to a more efficient stack machine format;  a more compact binary format generally means better loading time.
  • Equivalent human-readable text format for the purpose of reading, debugging, and occasionally handwriting WebAssembly.
  • Built-in JavaScript APIs to integrate WebAssembly modules to the web platform.
  • Up-to-date tools to produce WebAssembly modules, such as the Emscripten/Binaryen toolchain to convert C++ source to asm.js to WebAssembly, and WABT to convert between text and binary format.

To give you a taste of what WebAssembly looks like now, here is an example C++ recursive factorial function with its corresponding WebAssembly:

C++ factorial WebAssembly factorial function body
binary   | text
int factorial(int n)
if (n == 0)
return 1;
return n * factorial(n-1);
20 00    | get_local 0
42 00    | i64.const 0
51       | i64.eq
04 7e    | if i64
42 01    |   i64.const 1
05       | else
20 00    |   get_local 0
20 00    |   get_local 0
42 01    |   i64.const 1
7d       |   i64.sub
10 00    |   call 0
7e       |   i64.mul
0b       | end

The WebAssembly factorial function is extracted from the WebAssembly spec test.

We are eager to hear feedback from the community on WebAssembly. App authors should still expect changes and recompilation of apps for the MVP release, but any feedback from developing an app during the preview will help us make a better standard.

Implementation Progress in Microsoft Edge

We’ve been hard at work developing support for WebAssembly in Microsoft Edge at the open-source ChakraCore project repo. Microsoft Edge and ChakraCore are close to shipping the browser preview, which we expect to come when the full JavaScript APIs are implemented.

To demo the current capability of ChakraCore, we are also excited to showcase the AngryBots demo (with an updated WebAssembly binary) running in an internal build of Microsoft Edge. The demo loads faster than earlier versions compiled to asm.js or older WebAssembly formats, due to a more compact binary and ChakraCore’s new ability to defer parsing WebAssembly functions.

Over the next couple of months, our team will be focused on bringing the browser preview to Microsoft Edge. We look forward to continuing to contribute to the standardization of WebAssembly with the other browser vendors and the community, and would love to hear your thoughts about WebAssembly via @MSEdgeDev and @ChakraCore, or on the ChakraCore repo.

Limin Zhu, Program Manager, Chakra

Updated November 6, 2016 2:27 pm

Join the conversation

  1. Great! Fantastic to see that you’re working so hard and continuosly on standards, together with the industry and communities.

    If we have C++ for WebAssembly, what about C#? Someone working on a similar toolchain? What about Visual Studio integration? Maybe it would be cool to have support for the text format. Some code editor features on top and WABT integration for an out-of-the-box experience. And all the tooling for web development like debugging, performance analysis etc.? But I guess, you’re already working on some bits… 🙂 Looking forward to the preview!

    • Thanks for the question Robin! Something about C#->WebAssembly right now is that WebAssembly doesn’t have native GC, which members in the WebAssembly CG will consider after MVP. As WebAssembly gets more mature and adpoted, we’ll definitely look into support WebAssembly in our toolchains.

      Limin (MSFT)

  2. Very happy to see the major players working together for this one. Quick remark: shouldn’t the C++ example read “factorial(n-1)” rather than “fac(n-1)” ?

  3. Great work indeed. I would love to see a MS backed tool chain, starting with XAML/C# in VS and ending up in WASM-code in a browser. Something like Silverlight without plugin 🙂 Is this wishful thinking or kind of realistic in one or two years?