level up with webassembly
play

Level up with WebAssembly OSCON 2019 Robert Aboukhalil - PowerPoint PPT Presentation

Level up with WebAssembly OSCON 2019 Robert Aboukhalil @RobAboukhalil What is WebAssembly? What is WebAssembly? JavaScript WebAssembly char char * hello() { ( module module return return "Hello OSCON 2019!"; ( table table 0


  1. Level up with WebAssembly OSCON 2019 Robert Aboukhalil @RobAboukhalil

  2. What is WebAssembly?

  3. What is WebAssembly? JavaScript WebAssembly char char * hello() { ( module module return return "Hello OSCON 2019!"; ( table table 0 anyfunc) } ( memory memory $0 1) ( data data (i32.const 16) "Hello OSCON 2019!\00") ( export export "memory" (memory $0)) ( export export "hello" (func $hello)) ( func func $hello (; 0 ;) (result i32) (i32.const 16) ) ) WebAssembly Text (WAT) C++ WebAssembly = New language that runs in the browser Can compile C/C++/Rust/… to WebAssembly

  4. Why use WebAssembly?

  5. ① Port desktop apps Doom 3 to the web Google Earth AutoCAD

  6. ② Port command line sql.js tools to the web jqkungfu.com PyIodide

  7. ③ Targeted approach 1Password to speed up web apps eBay fastq.bio

  8. ④ WebAssembly Cloudflare Workers outside the web 🐎 💏 🐺 🐙 wasmer.io wasi.dev

  9. Why use WebAssembly? 💼 Portability Speed 📧 Sandbox

  10. Case Study Web app to analyze DNA sequencing data

  11. fastq.bio github.com/robertaboukhalil/fastq.bio

  12. Anatomy of a web app

  13. Browser Server 💼 UI Analysis Analysis ① JavaScript C/C++/Rust C/C++/Rust UI Analysis ② JavaScript JavaScript Pros: (1) No servers; (2) Works offline Cons: (1) Very slow; (2) Requires a rewrite

  14. Browser Server 💼 ☁ UI Analysis Analysis ① JavaScript C/C++/Rust C/C++/Rust UI Analysis ② JavaScript JavaScript UI Analysis ③ JavaScript C/C++/Rust → Wasm

  15. Compiling C code to WebAssembly Software: seqtk Normally: Emscripten: $ gcc seqtk.c \ $ emcc seqtk.c \ -O2 \ -O2 \ -o seqtk \ -o seqtk.js \ -lm \ -lm \ –lz -s USE_ZLIB=1 \ -s FORCE_FILESYSTEM=1 ./seqtk fqchk data.fastq Module.callMain(["fqchk", "data.fastq"]) github.com/lh3/seqtk

  16. Architecture Aioli WebWorker WebWorker API Controller app.js seqtk.wasm File System Plot results WebWorker Browser github.com/robertaboukhalil/fastq.bio github.com/robertaboukhalil/aioli npmjs.com/package/@robertaboukhalil/aioli

  17. fastq.bio v1 (JavaScript) v2 (WebAssembly)

  18. Performance Caveat: 9X speedup 13X speedup 21X speedup • Speedup not generalizable to all tools • Baseline = semi-opNmized JS

  19. Browser Server 💼 ☁ UI Analysis ① JavaScript C/C++/Rust UI Analysis ② JavaScript JavaScript UI Analysis ③ JavaScript C/C++/Rust → Wasm Pros: (1) No servers; (2) Works offline; (3) Speed; (4) Portability Cons: (1) Added complexity; (2) Unsupported browsers

  20. Serverless WebAssembly

  21. Browser Server Serverless 💼 ☁ 🌩 UI Analysis Analysis ① JavaScript C/C++/Rust C/C++/Rust UI Analysis ② JavaScript JavaScript UI Analysis ③ JavaScript C/C++/Rust → Wasm UI Analysis ④ JavaScript C/C++/Rust → Wasm

  22. Serverless WebAssembly: How? Approach 1 (AWS/GCP/Azure) Ÿ Use Node.js to execute WebAssembly Approach 2 (Fastly) Ÿ Use a WebAssembly runNme (Lucet) Ÿ IniNalizaNon Nme = 50µs! Approach 3 (Cloudflare Workers) Ÿ Use V8 isolates 🥬 Ÿ IniNalizaNon Nme = 5ms! Why is this a Big Deal TM ? Ÿ Sandbox ⇒ Fast initialization ⇒ No cold starts problem Ÿ Provider supports WebAssembly ⇒ Support C/C++/Rust/…

  23. Serverless WebAssembly app.js rust-bio → .wasm Cloudflare Worker Plot results Browser workers.cloudflare.com github.com/cloudflare/wrangler

  24. Serverless WebAssembly

  25. Browser Server Serverless 💼 ☁ 🌩 UI Analysis ① JavaScript C/C++/Rust UI Analysis ② JavaScript JavaScript UI Analysis ③ JavaScript C/C++/Rust → Wasm UI Analysis ④ JavaScript C/C++/Rust → Wasm Pros: (1) No servers; (2) Speed; (3) Portability; (4) Lightweight; (5) Process more data Cons: (1) Added complexity; (2) Cost of API calls; (3) Doesn’t work offline

  26. When to use WebAssembly

  27. When to use WebAssembly Graphics Ÿ Port games and desktop applicaNons to the web Data Tools Ÿ Image processing (e.g. photo/video ediNng) Ÿ Data analysis (e.g. fastq.bio) EducaSonal Tools Ÿ Playgrounds for command-line uNliNes (e.g. sqlite, jq) WebAssembly outside the web Ÿ WebAssembly + WASI Ÿ Serverless WebAssembly

  28. When not to use WebAssembly Ÿ Require lot of communication between JS & WASM Ÿ Need to analyze entire (large) file at once Ÿ Need large reference files loaded in memory Rule of Thumb: WebAssembly is awesome, but… Rule of Thumb: WebAssembly is awesome. but… Rule of Thumb: WebAssembly is awesome, but… Rule of Thumb: WebAssembly is awesome, but… assume YAGNI until you can prove otherwise. assume YAGNI until you can prove otherwise. assume YAGNI until you can prove otherwise. make sure you consider the tradeoffs

  29. levelupwasm.com COUPON CODE (15%): Please rate this session! OSCON2019

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend