Slide 1

Slide 1 text

@vladikoff WebAssembly for Front-end Developers

Slide 2

Slide 2 text

@vladikoff Vlad Filippov Toronto, Canada 󰎟 vf.io twitter.com/vladikoff github.com/vladikoff

Slide 3

Slide 3 text

@vladikoff

Slide 4

Slide 4 text

@vladikoff ~ December 2019

Slide 5

Slide 5 text

@vladikoff You probably already heard about WebAssembly... ● WebAssembly a.k.a WASM low-level bytecode format for the Web ● Supported by the popular browsers ● Stack-based virtual machine, produces *.wasm modules “New Kid on the Web: A Study on the Prevalence of WebAssembly in the Wild” https://www.sec.cs.tu-bs.de/pubs/2019a-dimva.pdf

Slide 6

Slide 6 text

@vladikoff Image processing, Barcode Scanner, Data visualization (muze, Perspective), cryptography, computer vision Figma, Text Editors & IDEs, 3D graphics, cross-environment tools Libraries - computation improvements - speeding up existing projects - image, audio & video processing - sharing code with node.js and other languages - import low-level components Custom Code Developer Tools Not so front-end’y Yew (Rust), Iced (Rust), Blazor (C#), Qt (C++), Vugu (Go) Frameworks - game development, SDKs - simulation software - crypto mining $$$$ - embedding languages - browser extensions - cloud functions & workers - the unknown! Front-end day-to-day work How do we use WebAssembly?

Slide 7

Slide 7 text

@vladikoff We have an app. But it’s slow*!

Slide 8

Slide 8 text

@vladikoff xxHash - an extremely fast non-cryptographic hash algorithm. Implementation in different languages. INPUT: “String” OUTPUT: 38F1791AF7DCE8B5 COMPUTE: XXH.h64(INPUT) 100 000 times

Slide 9

Slide 9 text

@vladikoff Okay, I’m going to write some WebAssembly...

Slide 10

Slide 10 text

@vladikoff Let’s optimize with WASM! github.com/appcypher/awesome-wasm-langs webassembly.studio

Slide 11

Slide 11 text

@vladikoff Replace with a WASM module... Compute... Main Thread Done!

Slide 12

Slide 12 text

@vladikoff Demo WASM modules

Slide 13

Slide 13 text

@vladikoff

Slide 14

Slide 14 text

@vladikoff Compute... Web Worker Main Thread createWasmWebWorker('parser.wasm').then(parser => { const result = parser.input(data); }); Done! Use web workers with WebAssembly... new Worker('worker.js');

Slide 15

Slide 15 text

@vladikoff Demo WASM web workers

Slide 16

Slide 16 text

@vladikoff

Slide 17

Slide 17 text

@vladikoff Firefox 79 includes support for WebAssembly threads. Check out Gerard Gallant’s article about using these in your projects.

Slide 18

Slide 18 text

@vladikoff bytecodealliance.org WASM beyond the browser... ● Using WebAssembly System Interfaces (WASI) to go run WASM beyond the browser. ● New software security model, useful for C++ and Rust, etc. ● WebAssembly speed to runtimes in Python, node.js, etc. open source community dedicated to creating secure new software foundations through WebAssembly Python node.js .NET

Slide 19

Slide 19 text

@vladikoff ● Use WebAssembly wisely - benchmark, optimize inputs, workers! ● WebAssembly might not always be a solution! ● Keep an eye on WASM module size and your WebPack output ● Check out the WASM case studies: AI/ML, eBay, fastq.bio, Figma, AutoCAD ● Follow the development of WebAssembly at hacks.mozilla.org!

Slide 20

Slide 20 text

@vladikoff Vlad Filippov @vladikoff github.com/vladikoff linkedin.com/in/vladikoff vf.io Thank you SmashingConf!

Slide 21

Slide 21 text

@vladikoff