WebAssembly

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

WebAssembly
Web Assembly Logo.svg
ParadigmImperative, structured, expression-oriented
Designed byW3C
Developer
First appearedMarch 2017; 1 year ago (2017-03)
Typing disciplineStatic
LicenseApache 2.0
Filename extensions
  • .wat
  • .wasm
Websitewebassembly.org
Influenced by

WebAssembly (often shortened to Wasm) is a standard that defines a binary format and a corresponding assembly-like text format for executables used by web pages.

The purpose of Wasm is to enable the JavaScript engine of a web browser to execute page scripts nearly as fast as native machine code. But this is not a full replacement for JavaScript; rather, Wasm is only intended for performance-critical portions of page scripts.[1][2][3] Wasm code runs in the same sandbox as regular script code, but only regular scripts have direct access to the DOM tree.

The World Wide Web Consortium (W3C) maintains the standard with contributions from Mozilla, Microsoft, Google, and Apple.[1]

History[edit]

WebAssembly was first announced in 2015,[4] and the first demonstration was executing Unity's Angry Bots in Firefox,[5] Google Chrome,[6] and Microsoft Edge.[7] The precursor technologies were asm.js from Mozilla and Google Native Client,[8][9] and the initial implementation was based on the feature set of asm.js.[10]

In March 2017, the design of the minimum viable product was declared to be finished and the preview phase ended.[11] In late September 2017, Safari 11 was released with support. In February 2018, the WebAssembly Working Group published three public working drafts for the Core Specification, JavaScript Interface, and Web API.[12][13][14][15]

Support[edit]

In November 2017, Mozilla declared support "in all major browsers",[16] after WebAssembly was enabled by default in Edge 16.[17] As of December 2018, roughly 80% of installed browsers support WebAssembly.[18] But for older browsers, Wasm can be compiled into asm.js by a JavaScript polyfill.[19]

Because WebAssembly executables are pre-compiled, it is possible to use a variety of programming languages to make them.[2] This is achieved either through direct compilation to Wasm, or through implementation of the corresponding virtual machines in Wasm. There have been around 40 programming languages reported to support Wasm as compilation target.[20]

Emscripten can compile to Wasm[11] using LLVM in the backend.

Its initial aim is to support compilation from C and C++,[21] though support for other source languages such as Rust and .NET languages is also emerging.[22][23][20] After the minimum viable product (MVP) release, there are plans to support multithreading and garbage collection[24] which would make WebAssembly a compilation target for garbage-collected programming languages like Java, C# (supported via Blazor) and Go.

Representation[edit]

WebAssembly code is intended to be run on a portable abstract structured stack machine,[25] which is designed to be faster to parse than JavaScript, as well as faster to execute,[21] and to enable very compact code representation.

In March 2017, the WebAssembly Community Group reached consensus on the initial (MVP) binary format, JavaScript API, and reference interpreter.[26] It defines a WebAssembly binary format, which is not designed to be used by humans, as well as a human-readable linear assembly bytecode format that resembles traditional assembly languages.

The table below represents three different views of the same source code input from the left, as it is converted to a Wasm intermediate representation, then to Wasm binary:[27]

C input source Linear assembly bytecode
(intermediate representation)
Wasm binary encoding
(hexadecimal bytes)
int factorial(int n) {
  if (n == 0)
    return 1;
  else
    return n * factorial(n-1);
}
get_local 0
i64.eqz
if (result i64)
    i64.const 1
else
    get_local 0
    get_local 0
    i64.const 1
    i64.sub
    call 0
    i64.mul
end
20 00
50
04 7E
42 01
05
20 00
20 00
42 01
7D
10 00
7E
0B

The WebAssembly text format can also be written in a folded format using s-expressions. This format is purely syntactic sugar and has no behavioral differences with the linear format.[28] An example is shown below:

(module
  (import "math" "exp" (func $exp (param f64) (result f64)))
  (func (export "doubleExp") (param $0 f64) (result f64)
    (f64.mul
      (call $exp
        (get_local $0)
      )
      (f64.const 2)
    )
  )
)

Literature[edit]

  • Haas, Andreas; Rossberg, Andreas; Schuff, Derek L.; Titzer, Ben L.; Gohman, Dan; Wagner, Luke; Zakai, Alon; Bastien, JF; Holman, Michael (June 2017). "Bringing the web up to speed with WebAssembly". Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation. Association for Computing Machinery: 185–200.
  • Watt, Conrad (2018). "Mechanising and Verifying the WebAssembly Specification" (PDF). ACM SIGPLAN International Conference on Certified Programs and Proofs. ACM. 7. doi:10.1145/3167082.

References[edit]

  1. ^ a b Bright, Peter (18 June 2015). "The Web is getting its bytecode: WebAssembly". Ars Technica. Condé Nast.
  2. ^ a b Ball, Kevin (June 26, 2018). "How WebAssembly is Accelerating the Future of Web Development". Archived from the original (HTML) on 2019-02-12. Retrieved 2018-10-22.
  3. ^ "Is WebAssembly trying to replace JavaScript?".
  4. ^ "Launch bug". GitHub / WebAssembly / design. 11 June 2015.
  5. ^ Wagner, Luke (14 March 2016). "A WebAssembly Milestone: Experimental Support in Multiple Browsers". Mozilla Hacks.
  6. ^ Thompson, Seth (15 March 2016). "Experimental support for WebAssembly in V8". V8 Blog.
  7. ^ Zhu, Limin (15 March 2016). "Previewing WebAssembly experiments in Microsoft Edge". Microsoft Edge dev blog.
  8. ^ Lardinois, Frederic (2015-06-17). "Google, Microsoft, Mozilla And Others Team Up To Launch WebAssembly, A New Binary Format For The Web". TechCrunch. Retrieved 2017-12-24.
  9. ^ Avram, Abel (2017-05-31). "Google Is to Remove Support for PNaCl". InfoQ. Retrieved 2017-12-22.
  10. ^ "WebAssembly: a binary format for the web". ②ality – JavaScript and more. 18 June 2015.
  11. ^ a b Krill, Paul (2017-03-06). "WebAssembly is now ready for browsers to use". InfoWorld. Retrieved 2017-12-23.
  12. ^ "WebAssembly First Public Working Drafts". W3C. February 15, 2018. Retrieved April 20, 2018.
  13. ^ "WebAssembly Core Specification". W3C. February 15, 2018. Retrieved April 20, 2018.
  14. ^ "WebAssembly JavaScript Interface". W3C. February 15, 2018. Retrieved April 20, 2018.
  15. ^ "WebAssembly Web API". W3C. February 15, 2018. Retrieved April 20, 2018.
  16. ^ "WebAssembly support now shipping in all major browsers". The Mozilla Blog. Retrieved 2017-11-21.
  17. ^ "Introducing new JavaScript optimizations, WebAssembly, SharedArrayBuffer, and Atomics in EdgeHTML 16". Microsoft Edge Dev Blog. Retrieved 2017-11-21.
  18. ^ "WebAssembly". Can I use. Retrieved 2018-12-04.
  19. ^ Bright, Peter (2015-06-18). "The Web is getting its bytecode: WebAssembly". Ars Technica. Retrieved 2017-12-23.
  20. ^ a b "Awesome WebAssembly Languages". June 26, 2018. Archived from the original (HTML) on 2019-02-12. Retrieved 2019-02-12.
  21. ^ a b "WebAssembly High-Level Goals". GitHub / WebAssembly / design. 11 December 2015.
  22. ^ Krill, Paul (2017-11-29). "Direct WebAssembly compilation comes to Rust language". InfoWorld. Retrieved 2017-12-24.
  23. ^ "Frequently asked questions (FAQ) about Blazor". blazor.net. Retrieved 2018-06-18.
  24. ^ Krill, Paul (2017-10-26). "What's next for WebAssembly: GC, threads, debugging". TechWorld. Retrieved 2017-12-24.
  25. ^ "Design Rationale". GitHub / WebAssembly / design. 1 October 2016.
  26. ^ "Roadmap". WebAssembly. March 2017.
  27. ^ jfbastien; rossberg-chromium; kripken; titzer; s3ththompson; sunfishcode; lukewagner; flagxor; enricobacis; c3d; binji; andrewosh (9 March 2017). "Text Format". WebAssembly/design. GitHub.
  28. ^ "Folded instructions". GitHub. / WebAssembly / spec

Definition of Free Cultural Works logo notext.svg This article incorporates text from a free content work. Licensed under Apache License 2.0 License statement: Text Format, jfbastien; rossberg-chromium; kripken; titzer; s3ththompson; sunfishcode; lukewagner; flagxor; enricobacis; c3d; binji; andrewosh, GitHub. WebAssembly/design. To learn how to add open license text to Wikipedia articles, please see Wikipedia:Adding open license text to Wikipedia. For information on reusing text from Wikipedia, please see the terms of use.

External links[edit]