36
Bringing the Web Up to Speed with WebAssembly Matthew Furlong, Drew Davis, Ayush Goel, Umang Lathia

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

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

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

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

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

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

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

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

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

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

... 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

... 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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