WebAssembly
WebAssembly (often shortened to Wasm) is a standard that defines a portable binary format and a corresponding assembly-like text format for executables.
The main goal of WebAssembly is to enable high performance applications on web pages, but it is designed to be executed and integrated in other environments as well.[1] But this is not a full replacement for JavaScript; rather, Wasm is only intended for performance-critical portions of page scripts.[2][3][4] 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.[2]
History
WebAssembly was first announced in 2015,[5] and the first demonstration was executing Unity's Angry Bots in Firefox,[6] Google Chrome,[7] and Microsoft Edge.[8] The precursor technologies were asm.js from Mozilla and Google Native Client,[9][10] and the initial implementation was based on the feature set of asm.js.[11]
In March 2017, the design of the minimum viable product was declared to be finished and the preview phase ended.[12] 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.[13][14][15][16]
Support
In November 2017, Mozilla declared support "in all major browsers",[17] after WebAssembly was enabled by default in Edge 16.[18] The support includes mobile web browsers for iOS and Android. As of May 2018, 85.8% of installed browsers (and 87.83% of desktop browsers) support WebAssembly.[19] But for older browsers, Wasm can be compiled into asm.js by a JavaScript polyfill.[20]
Because WebAssembly executables are pre-compiled, it is possible to use a variety of programming languages to make them.[3] 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 a compilation target.[21]
Emscripten can compile C and C++ to Wasm[12] using LLVM in the backend.
Its initial aim is to support compilation from C and C++,[22] though support for other source languages such as Rust and .NET languages is also emerging.[23][24][21] After the minimum viable product (MVP) release, there are plans to support multithreading and garbage collection[25] which would make WebAssembly a compilation target for garbage-collected programming languages like Java, Julia,[26][27] C# (supported via Blazor), and Go.
Beyond the Browser
While WebAssembly was initially designed to enable near-native code execution speed in the web browser, it has been considered valuable outside of such, in more generalized contexts.[28][29]
WebAssembly System Interface (WASI) is an ABI designed by Mozilla intended to define a simpler ABI for WebAssembly that can be used in any platform.[30] There are also a few other proposed ABI APIs.[31][32]
Representation
WebAssembly code is intended to be run on a portable abstract structured stack machine,[33] which is designed to be faster to parse than JavaScript, as well as faster to execute,[22] 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.[34] 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:[35]
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.[36] 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
- 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. doi:10.1145/3062341.3062363.
- 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
- ^ "WebAssembly Specification Release 1.0 (Draft, last updated Apr 16, 2019): Introduction". webassembly.org. Retrieved 6 May 2019.
- ^ a b Bright, Peter (18 June 2015). "The Web is getting its bytecode: WebAssembly". Ars Technica. Condé Nast.
- ^ a b Ball, Kevin (26 June 2018). "How WebAssembly is Accelerating the Future of Web Development". Archived from the original (HTML) on 12 February 2019. Retrieved 22 October 2018.
- ^ "Is WebAssembly trying to replace JavaScript?".
- ^ "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.
- ^ Lardinois, Frederic (17 June 2015). "Google, Microsoft, Mozilla And Others Team Up To Launch WebAssembly, A New Binary Format For The Web". TechCrunch. Retrieved 24 December 2017.
- ^ Avram, Abel (31 May 2017). "Google Is to Remove Support for PNaCl". InfoQ. Retrieved 22 December 2017.
- ^ "WebAssembly: a binary format for the web". ②ality – JavaScript and more. 18 June 2015.
- ^ a b Krill, Paul (6 March 2017). "WebAssembly is now ready for browsers to use". InfoWorld. Retrieved 23 December 2017.
- ^ "WebAssembly First Public Working Drafts". W3C. 15 February 2018. Retrieved 20 April 2018.
- ^ "WebAssembly Core Specification". W3C. 15 February 2018. Retrieved 20 April 2018.
- ^ "WebAssembly JavaScript Interface". W3C. 15 February 2018. Retrieved 20 April 2018.
- ^ "WebAssembly Web API". W3C. 15 February 2018. Retrieved 20 April 2018.
- ^ "WebAssembly support now shipping in all major browsers". The Mozilla Blog. Retrieved 21 November 2017.
- ^ "Introducing new JavaScript optimizations, WebAssembly, SharedArrayBuffer, and Atomics in EdgeHTML 16". Microsoft Edge Dev Blog. Retrieved 21 November 2017.
- ^ "WebAssembly". Can I use. Retrieved 3 May 2019.
- ^ Bright, Peter (18 June 2015). "The Web is getting its bytecode: WebAssembly". Ars Technica. Retrieved 23 December 2017.
- ^ a b "Awesome WebAssembly Languages". 26 June 2018. Archived from the original (HTML) on 12 February 2019. Retrieved 12 February 2019.
- ^ a b "WebAssembly High-Level Goals". GitHub / WebAssembly / design. 11 December 2015.
- ^ Krill, Paul (29 November 2017). "Direct WebAssembly compilation comes to Rust language". InfoWorld. Retrieved 24 December 2017.
- ^ "Frequently asked questions (FAQ) about Blazor". blazor.net. Retrieved 18 June 2018.
- ^ Krill, Paul (26 October 2017). "What's next for WebAssembly: GC, threads, debugging". TechWorld. Retrieved 24 December 2017.
- ^ "Julia in the Browser". nextjournal.com. Retrieved 9 April 2019.
- ^ "WebAssembly platform by tshort · Pull Request #2 · JuliaPackaging/Yggdrasil". GitHub. Retrieved 9 April 2019.
- ^ "Non-Web Embeddings". WebAssembly. Retrieved 15 May 2019.
- ^ "Non-Web Embeddings". GitHub / WebAssembly. Retrieved 15 May 2019.
- ^ "WebAssembly System Interface Repo". GitHub / WebAssembly.
- ^ "reference-sysroot Repo". GitHub / WebAssembly.
- ^ "wasm-c-api Repo". GitHub / WebAssembly.
- ^ "Design Rationale". GitHub / WebAssembly / design. 1 October 2016.
- ^ "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 this how-to page. For information on reusing text from Wikipedia, please see the terms of use.
Demo
- Widgets demo: [1] with NWSTK
- 3D mountain geometry synthesis demo: [2] with NWSTK
- Demo for loading and drawing a jpg file: [3] with NWSTK
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)