WebAssembly
WebAssembly (Wasm, WA) is a web standard that defines a binary format and a corresponding assembly-like text format for executable code in Web pages. It is meant to enable executing code nearly as quickly as running native machine code. It was envisioned to complement JavaScript to speed up performance-critical parts of web applications and later on to enable web development in languages other than JavaScript.[1][2][3][4] WebAssembly does not attempt to replace JavaScript, but to complement it.[5] It is developed at the World Wide Web Consortium (W3C) with engineers from Mozilla, Microsoft, Google, and Apple.[6]
It is executed in a sandbox in the web browser after a verification step. Programs can be compiled from high-level languages into Wasm modules and loaded as libraries from within JavaScript applets.
Design
WebAssembly code is intended to be run on a portable abstract structured stack machine,[7] which is designed to be faster to parse than JavaScript, as well as faster to execute,[8] and to enable very compact code representation.
History
Vendor-specific precursor technologies are Google Native Client (NaCl) and asm.js.[1][9] The initial implementation of WebAssembly support in browsers was based on the feature set of asm.js.[10] It was first announced on 17 June 2015[11] and on 15 March 2016 was demonstrated executing Unity's Angry Bots in Firefox,[12] Chromium, Google Chrome,[13] and Microsoft Edge.[14] In March 2017, the design of the minimum viable product was declared to be finished and the preview phase ended.[15] In late September 2017, Safari 11 was released with support. As of December 2018, the website Can I use tracks 80.54% global web browser support for WebAssembly (and indirectly, through polyfill, others are supported).[16] In February 2018 the WebAssembly Working Group published three public working drafts for the Core Specification, JavaScript Interface, and Web API.[17][18][19][20]
Support
In November 2017, Mozilla declared support "in all major browsers",[21] after WebAssembly was enabled by default in Edge 16.[22] For backward compatibility, Wasm can be compiled into asm.js by a JavaScript polyfill and executed on incompatible browsers this way.[23]
Emscripten can compile to Wasm[15] using LLVM in the backend.
Its initial aim is to support compilation from C and C++,[8] though support for other source languages such as Rust and .NET languages is also emerging.[24][25] After the minimum viable product (MVP) release, there are plans to support garbage collection[26] which would make WebAssembly a compilation target for garbage-collected programming languages like Java, C# (supported via Blazor) and Go.
Representation
In March 2017, the WebAssembly Community Group reached consensus on the initial (MVP) binary format, JavaScript API, and reference interpreter.[27] 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:[28]
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.[29] 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)
)
)
)
See also
- XAML Browser Applications (XBAP)
- Blazor – WebAssembly-based framework for C#
Literature
- 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
- ^ a b 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.
- ^ Cimpanu, Catalin (2015-06-18). "Mozilla, Microsoft, Google, and Apple Join Efforts to Create a Binary File Format for the Web". softpedia. Retrieved 2017-12-23.
- ^ Hoffmann, Moritz (2015-06-23). "Turbo-Boost für JavaScript: Eric Elliott über WebAssembly". JAXenter (in German). Retrieved 2017-12-23.
- ^ Ball, Kevin (June 26, 2018). "How WebAssembly is Accelerating the Future of Web Development". Archived from the original (HTML) on 2018-10-22. Retrieved 2018-10-22.
- ^ "Is WebAssembly trying to replace JavaScript?".
- ^ Bright, Peter (18 June 2015). "The Web is getting its bytecode: WebAssembly". Ars Technica. Condé Nast.
- ^ "Design Rationale". GitHub / WebAssembly / design. 1 October 2016.
- ^ a b "WebAssembly High-Level Goals". GitHub / WebAssembly / design. 11 December 2015.
- ^ Avram, Abel (2017-05-31). "Google Is to Remove Support for PNaCl". InfoQ. Retrieved 2017-12-22.
- ^ "WebAssembly: a binary format for the web". ②ality – JavaScript and more. 18 June 2015.
- ^ "Launch bug". GitHub / WebAssembly / design. 11 June 2015.
- ^ Wagner, Luke (14 March 2016). "A WebAssembly Milestone: Experimental Support in Multiple Browsers". Mozilla Hacks.
- ^ Thompson, Seth (15 March 2016). "Experimental support for WebAssembly in V8". V8 Blog.
- ^ Zhu, Limin (15 March 2016). "Previewing WebAssembly experiments in Microsoft Edge". Microsoft Edge dev blog.
- ^ a b Krill, Paul (2017-03-06). "WebAssembly is now ready for browsers to use". InfoWorld. Retrieved 2017-12-23.
- ^ "WebAssembly". Can I use. Retrieved 2018-12-04.
- ^ "WebAssembly First Public Working Drafts". W3C. February 15, 2018. Retrieved April 20, 2018.
- ^ "WebAssembly Core Specification". W3C. February 15, 2018. Retrieved April 20, 2018.
- ^ "WebAssembly JavaScript Interface". W3C. February 15, 2018. Retrieved April 20, 2018.
- ^ "WebAssembly Web API". W3C. February 15, 2018. Retrieved April 20, 2018.
- ^ "WebAssembly support now shipping in all major browsers". The Mozilla Blog. Retrieved 2017-11-21.
- ^ "Introducing new JavaScript optimizations, WebAssembly, SharedArrayBuffer, and Atomics in EdgeHTML 16". Microsoft Edge Dev Blog. Retrieved 2017-11-21.
- ^ Bright, Peter (2015-06-18). "The Web is getting its bytecode: WebAssembly". Ars Technica. Retrieved 2017-12-23.
- ^ Krill, Paul (2017-11-29). "Direct WebAssembly compilation comes to Rust language". InfoWorld. Retrieved 2017-12-24.
- ^ "Frequently asked questions (FAQ) about Blazor". blazor.net. Retrieved 2018-06-18.
- ^ Krill, Paul (2017-10-26). "What's next for WebAssembly: GC, threads, debugging". TechWorld. Retrieved 2017-12-24.
- ^ "Roadmap". WebAssembly. March 2017.
- ^ jfbastien; rossberg-chromium; kripken; titzer; s3ththompson; sunfishcode; lukewagner; flagxor; enricobacis; c3d; binji; andrewosh (9 March 2017). "Text Format". WebAssembly/design. GitHub.
- ^ "Folded instructions". GitHub. / WebAssembly / spec
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
- Official website
- W3C Community Group
- WebAssembly Design
- "WebAssembly". MDN Web Docs. – with info on browser compatibility and specifications (WebAssembly JavaScript API)
- WebAssembly: What and What Next? (youtube)