the nuts and bolts of webassembly
play

The nuts and bolts of WebAssembly by Srikumar K. S. Director, - PowerPoint PPT Presentation

The nuts and bolts of WebAssembly by Srikumar K. S. Director, Technology Pramati Technologies Pvt. Ltd. Mixed Nuts @ Pramati meetup 2019-08-24, Chennai History Web Tech Speed meant plugins ex: Flash , SilverLight SlowJS era '00 '01 '02 '03


  1. The nuts and bolts of WebAssembly by Srikumar K. S. Director, Technology Pramati Technologies Pvt. Ltd. Mixed Nuts @ Pramati meetup 2019-08-24, Chennai

  2. History

  3. Web Tech Speed meant plugins ex: Flash , SilverLight SlowJS era '00 '01 '02 '03 '04 '05 '06 '07 '08 '09 '10 '11 '12 '13 '14 '15 '16 '17 '18 '19 First release of LLVM Core Tech

  4. Optimize CodeGen Machine Backend 1 Code 1 CodeGen Machine IR Src Compile Tokens AST Lex Parse Backend 2 Code 2 CodeGen Machine Backend 3 Code 3 LLVM IR

  5. (p)NaCl 
 Web axed announced Meetup @ Pramati Tech asm.js WASM in Firefox 22 MVP and JIT for (p)NaCl Speed meant plugins WASM Javascript announced ex: Flash , SilverLight announced SlowJS era '00 '01 '02 '03 '04 '05 '06 '07 '08 '09 '10 '11 '12 '13 '14 '15 '16 '17 '18 '19 First release LLVM announces Safari Nitro of LLVM Clang frontend applies stable Rust-lang LLVM for 30% speedup Core Tru ffl e announced GraalVM first (towards GraalVM ) Tech production release

  6. 
 Edge 16 Firefox 52 
 supports wasi-sdk-1 supports supports WASM WASM Golang (clang) Meetup @ Pramati wasm32-uk-uk 1.11 support 1.36 with for WASM wasm32-wasi wasmer.io Safari 11 iOS Safari 11 
 launched WASI WebAssembly supports supports WASM announced MVP announced WASM '18 '19 '17 Chrome 57 Cloudflare 
 Cloudflare 
 supports Workers 
 open sources Workers 
 WASM Lucet support 
 announced WASM ( V8 Isolates ) Chrome 75 
 1.14 supports Android Browser Android WASM announces supports supports Terrarium (emscripten) WASM WASM

  7. Walk through

  8. Setup • Install the Emscripten SDK - 
 https://emscripten.org/docs/getting_started/downloads.html • Install the WASI SDK - 
 https://github.com/CraneStation/wasi-sdk/releases 
 (installs to /opt/wasi-sdk ) • Install webassembly npm module - 
 npm install webassembly • Install wabt - 
 https://github.com/WebAssembly/wabt/releases • Install wasmer - 
 curl https://get.wasmer.io -sSfL | sh

  9. Baby steps - pythagorus.c Did you npm install webassembly ?

  10. Baby steps - pythagorus.js wa compile pythagorus.c -o pythagorus.wasm

  11. Baby steps - pythagorus.wasm wa compile pythagorus.c -o pythagorus.wasm wasm-dis pythagorus.wasm // Like what you see? (haha!) wa compile -O pythagorus.c -o pythagorus.wasm wasm-dis pythagorus.wasm > pythagorus.wast

  12. Baby steps - pythagorus.wast type decl pythagorus(x,y) x ² +y ² x ² x y y ²

  13. S-expressions ( operator arg1 arg2 … argN) ( operator arg1 ( op2 y1 y2) … argN)

  14. S-expressions ( sqrt ( add ( mul x x) ( mul y y)))

  15. S-expressions - evaluation ( op1 arg1 ( op2 arg2 arg3)) Postorder tree traversal ! arg1 arg2 arg3 op2 op1

  16. S-expressions - evaluation $0 local.get $0 local.get f64.mul $1 local.get $1 local.get f64.mul f64.add f64.sqrt

  17. wasm2wat pythagorus.wasm

  18. Something more useful

  19. WASM machine model Memory ( ) funcref table Funcref Index 0x1135762 1 0x9498627 2 WASM 0x9282463 3 Exports / Imports CODE Name Fn crunch 2 mumble 7 dig 11

  20. Getting real with WASI ucase.c

  21. Getting real with WASI SYSROOT=/home/srikumar/wasi-sdk-6.0/opt/wasi-sdk/share/wasi-sysroot/ clang -O3 --sysroot $SYSROOT ucase.c -o ucase.wasm Set <SYSROOT> to the sysroot folder of your wasi-sdk, or omit --sysroot parameter if you installed wasi-sdk at the default location - /opt wasmer run ucase.wasm ucase.c /tmp/out.c Input denied! wasmer run --dir=. --mapdir=/tmp:output ucase.wasm ucase.c /tmp/out.c

  22. Where is all this heading?

  23. Signal processing in the browser Opus codec - https://github.com/srikumarks/webopus (shameless plug - patantara.com)

  24. Core cloud principles • Fast deployment • Fast startup time • Fast runtime • Low memory overhead • Secure execution

  25. Capability based security sandstorm.io Google Fuchsia OS You can ONLY access resources you’ve been handed!

  26. Capability based security Chandra Anitha 348-4687 239-4867 Balu 239-4867 694-8673 694-8673 348-4687 You can ONLY access resources you’ve been handed!

  27. CloudABI https://cloudabi.org • Capability based runtime for UNIX programs • No command line arguments • No environment variables • Cannot take ANY action that a ff ects global system • => WebAssembly and CloudABI are MFEO!

  28. CloudABI https://cloudabi.org cloudabi_errno_t cloudabi_sys_file_open( cloudabi_lookup_t dirfd , const char *path, size_t path_len, cloudabi_oflags_t oflags, const cloudabi_fdstat_t *fds, cloudabi_fd_t *fd 
 );

  29. CloudABI https://cloudabi.org cloudabi_errno_t cloudabi_sys_sock_recv( cloudabi_fd_t sock , No sock_create() !! const cloudabi_recv_in_t *in, cloudabi_recv_out_t *out); cloudabi_errno_t cloudabi_sys_sock_send( cloudabi_fd_t sock , const cloudabi_send_in_t *in, cloudabi_send_out_t *out); cloudabi_errno_t cloudabi_sys_sock_shutdown( cloudabi_fd_t sock , cloudabi_sdflags_t how);

  30. Running code at the edge Javascript WebAssembly Workers Terrarium / Lucet

  31. Running code in the kernel https://github.com/wasmerio/kernel-wasm Faster IO than user mode. eBPF in WASM?

  32. Trusted computing https://github.com/project-oak/ eWASM Isolated secure enclaves with WASM for e2e encrypted communication. Ethereum

  33. Wrapping up

  34. Possible efficiencies • Pre-compiled code is fast to start • Prepare initialized memory once and reuse it • Cache friendliness - use languages where you control memory • One-time optimizations worth the cost

  35. Possible inefficiencies • Data needs to be copied in and out. 
 (Improvements in the works, though) • No vectorization (yet). SIMD support is coming. • No threads (yet) … though we can use workers • Not 64-bit enabled (yet)

  36. Where to use • Fast startup/shutdown times • Large compute relative to data transfer • Strong security guarantees needed, without full VM overhead • Portability of existing desktop software and libraries for use within browsers is important - ex: simulated development environments, KrakenD API gateway.

  37. Where not to use • If security is not a concern for running plug-n-play code, consider JS. Its pretty darned good. • Relatively little compute to compensate for the extra data copy. 
 (There are ways to avoid the copy) • If binary portability doesn’t buy you much - ex: known server environments and trusted code - consider native code.

  38. Speculative Other possibilities • WASM for deploying machine learning models? • WASM code as Kafka stream processors? • WASM for database UDFs? • WASM for FPGA ( https://github.com/piranna/wasmachine ) • WASM in network controllers? • WASM for web applications (duh!) ( https://github.com/yewstack/yew ) • WASM on bare metal, hypervisors?

  39. Happy assembling!

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