Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scotland JS 2018 - Hacker's guide to Web Assembly

Scotland JS 2018 - Hacker's guide to Web Assembly

Starting from the basics, this talk will walk you through what web assembly is, and then why it’s fast.

vigneshwer dhinakaran

July 19, 2018
Tweet

More Decks by vigneshwer dhinakaran

Other Decks in Technology

Transcript

  1. History! • Java Applets • ActiveX • NaCl • asm.js

    - Separate VM - No DOM integration - Limited to a sandbox env. - Optimizable, low-level subset of JavaScript WASM is a direct successor of asm.js
  2. Running Code on the Web! (Performing Complex Operations) Js C/

    C++/ Rust .. - WebAssembly brings other programming languages than Js to the Web! - Bringing Native performance to Web JS Engines (JIT Compiler) Wasm Modules
  3. Rust C++ C IR ARM x86 Front-end tools Back-end tools

    With help of LLVM toolchain , compilations to n + m times
  4. Rust C++ C IR ARM x86 Wasm Running system programming

    code on Web! clang Rustc Optimizer: LLVM LLVM Wasm Backend Decode Compile & Optimize Execute
  5. WebAssembly is an open standard supported by all major browsers.

    https://hacks.mozilla.org/2017/02/where-is-webassembly-now-and-whats-next/
  6. Why is webassembly so fast? 1. Less time to download

    | Smaller in size & Compact 2. Optimized Code | Compiled ahead of time 3. Executes at native speed by taking advantage of common hardware capabilities 4. Better memory mgmt!
  7. Going to Production! Making WebAssembly better for Rust & for

    all languages https://hacks.mozilla.org/2018/03/making-webassembly-better-for-rust-for-all-languages/
  8. Why Rust? Freedom from Data Race conditions Strong type system

    High level iterators More control over memory Welcoming Community
  9. wasm-bindgen Facilitating high-level interactions between wasm modules and JavaScript https://github.com/rustwasm/wasm-bindgen

    Steps: 1. Import JavaScript things into Rust and export Rust things to JavaScript 2. Use exported Rust things from JavaScript! https://hacks.mozilla.org/2018/04/javascript-to-rust-and-back-agai n-a-wasm-bindgen-tale/
  10. What does wasm32-unknown-unknown mean? - {architecture}-{vendor}-{system} - Cross compiling Rust

    programs for different machines FAQs What does cdylib stand for? - cdylib stands for exporting a C interface from a Rust dynamic library
  11. Supporting Older browsers? C/C++ ---> asm.js ---> .Wasm (Binaryen tool)

    - LLVM bytecode to Js - Compiling Heavy Code FAQs
  12. Yew Yew is a modern Rust framework inspired by Elm

    and ReactJS for creating multi-threaded frontend apps with WebAssembly https://github.com/DenisKolodin/yew https://www.youtube.com/watch?v=qszZTwG0nZs
  13. Applications: 1. Games (e.g., Unreal, Unity) 2. Multimedia (e.g., AV1,

    FLIF, BPG) 3. Performance (e.g., KeeWeb, Mega) 4. Libraries (e.g., OpenCV, Box2D, LibSass) 5. 64-bit Math (e.g., MAME, SHA512)
  14. Reasons to Use WebAssembly: Wasm provides :- 1. Great Runtime

    Performance 2. Code Reusability 3. Portability 4. Enables new designs (WASM + Js)
  15. What is WebAssembly, again? A compiler target for the Web:

    1. Low-level, binary format for programs 2. Open standard with cross-browser support 3. Direct successor of asm.js 4. General purpose virtual architecture