Bringing the Web Up to Speed with...
Transcript of Bringing the Web Up to Speed with...
![Page 1: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/1.jpg)
Bringing the Web Up to Speed with
WebAssembly
Matthew Furlong, Drew Davis, Ayush Goel, Umang Lathia
![Page 2: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/2.jpg)
An Open Standard
![Page 3: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/3.jpg)
An Open Standard
These 4 browsers have a 90 percent
market share!
![Page 4: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/4.jpg)
Outline1. Introduction and Motivation2. Overview and Execution3. Validation4. Binary Format & Embedding5. Evaluation
![Page 5: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/5.jpg)
The Web● “The most ubiquitous
application platform ever.”
![Page 6: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/6.jpg)
The Web● “The most ubiquitous
application platform ever.”● Yet Javascript is the only
natively supported programming language on the web...
![Page 7: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/7.jpg)
Away from Javascript...● Web applications are more demanding than ever
○ 3D Visualization○ Audio and Video software○ Games
● Many developers don’t want to use Javascript
![Page 8: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/8.jpg)
... and Onto WebAssembly!● A low-level, language independent bytecode for the Web
![Page 9: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/9.jpg)
... and Onto WebAssembly!● A low-level, language independent bytecode for the Web● Goals
○ Safe○ Fast○ Portable○ Compact
![Page 10: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/10.jpg)
Previous Work on Bytecode for the Web● Microsoft’s ActiveX● Native Client and Portable Native Client● asm.js
![Page 11: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/11.jpg)
Previous Work on Bytecode for the Web● Microsoft’s ActiveX● Native Client and Portable Native Client● asm.js
WebAssembly is the first solution for low-level code on the Web that provides safety, speed, portability, and small code
sizes.
![Page 12: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/12.jpg)
Outline1. Introduction and Motivation2. Overview and Execution3. Validation4. Binary Format & Embedding5. Evaluation
![Page 13: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/13.jpg)
Overview● A binary code format, not a language ● Basic language features
○ Modules○ Functions○ Instructions○ Traps○ ….
![Page 14: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/14.jpg)
Overview● New Language features
○ Linear memory ( also known as flat memory)○ Endiannes
■ Little endian○ Structured Control Flow
■ Eliminates problems caused by simply jumps■ Blocks execute like function calls
○ Function calls
![Page 15: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/15.jpg)
Overview● Determinism
○ Design semantics tries to minimize non determinism due to corner cases.
○ Implementation dependent behavior ■ NaNs■ Resource Exhaustion■ Host Functions
![Page 16: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/16.jpg)
Execution● Uses a global store object ( like Windows in Browsers)
● Stores and Runtime objects representation
● Reduction Rules
![Page 17: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/17.jpg)
Outline1. Introduction and Motivation2. Overview and Execution3. Validation4. Binary Format & Embedding5. Evaluation
![Page 18: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/18.jpg)
Validation
Untrusted Server
Local Browser
WebAssembly Code
![Page 19: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/19.jpg)
Validation● Defined as a simple type system● Efficiently checkable in a single linear pass
![Page 20: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/20.jpg)
Validation● Typing Rules
○ Ensure that the types for every instruction sequence are correct
● Soundness○ Typing rules cover all possible states (no undefined
behavior)■ Guarantees memory safety and inaccessibility of
code addresses or call stack
![Page 21: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/21.jpg)
Outline1. Introduction and Motivation2. Overview and Execution3. Validation4. Binary Format & Embedding5. Evaluation
![Page 22: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/22.jpg)
Binary Format● Code transmitted across web as a binary encoding
○ Binary code organized by entities■ Streaming compilation ■ Parallelized compilation
○ Instructions - one-byte opcodes○ Integral numbers - LEB128 format
![Page 23: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/23.jpg)
Embedding● WebAssembly is designed to be embedded into an
execution environment● Therefore, does not define:
○ How programs are loaded into execution environment○ How I/O is performed
![Page 24: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/24.jpg)
Outline1. Introduction and Motivation2. Overview and Execution3. Validation4. Binary Format & Embedding5. Evaluation
![Page 25: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/25.jpg)
Implementation● Lots of different JavaScript engines
○ V8 (Chrome), SpiderMonkey (Mozilla), Chakra (Edge)
● Developed independent implementations for each browser○ On-the-fly validation (as fast as 1 GB/s)○ SSA (V8 and SpiderMonkey) → direct-to-SSA in a single pass
● Other Optimizations○ Bounds Check - Constant-fold memsize - offset ○ Parallel Compilation (5-6x improvement)○ Compiled code caching (memoization)
![Page 26: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/26.jpg)
Measurements Execution time of PolyBenchC benchmarks on Webassembly normalized to native code
![Page 27: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/27.jpg)
Measurements Execution time of PolyBenchC benchmarks on Webassembly normalized to native code
7 benchmarks within 10% of nativeAlmost all within 2x of native
![Page 28: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/28.jpg)
Measurements Execution time of PolyBenchC benchmarks on Webassembly normalized to native code
33.7% faster than asm.js (validation
much faster)
![Page 29: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/29.jpg)
Measurements Binary size of WebAssembly in comparison to asm.js and native code
![Page 30: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/30.jpg)
Measurements Binary size of WebAssembly in comparison to asm.js and native code
62.5% size of asm.js85.3% size of native x86
![Page 31: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/31.jpg)
Measurements Binary size of WebAssembly in comparison to asm.js and native code
![Page 32: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/32.jpg)
Evaluation● Strength
○ Ability to write in any language
○ Faster compilation
○ Compact
○ Fast
● Weaknesses○ Separate compiler to port each language to WebAssembly
![Page 33: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/33.jpg)
Road Map● MVP Completed (3 years ago)● Features in process:
○ Exception handling○ Threads○ Garbage Collection○ Single Instruction Multiple Data instructions○ Tail Calls
https://webassembly.org/docs/future-features/
![Page 34: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/34.jpg)
Community & Current Updates
![Page 35: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/35.jpg)
Questions?
![Page 36: Bringing the Web Up to Speed with WebAssemblyweb.eecs.umich.edu/~mahlke/courses/583f18/lectures/Dec3/talk4.pdf · Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew](https://reader033.fdocuments.us/reader033/viewer/2022053011/5f0ef2c47e708231d441bad7/html5/thumbnails/36.jpg)
Appendix A - Why is WebAssembly faster than asm.js?
● Startup○ Smaller to download, faster to parse
● CPU features
○ asm.js doesn’t have access to CPU features -- slower
●