a type system for javascript with fixed object layoutwontae choi @ static analysis symposium 2015...

64
SJS: A Type System for JavaScript with Fixed Object Layout Wontae Choi * , Satish Chandra + , George Necula * , and Koushik Sen * SAS 2015 @ Saint-Malo, France * University of California, Berkeley + Samsung Research America This project started during a summer internship of the first author at Samsung Research America in 2013 and 2014.

Upload: others

Post on 26-Apr-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

SJS: A Type System for JavaScript

with Fixed Object LayoutWontae Choi*, Satish Chandra+, George Necula*, and Koushik Sen*

SAS 2015 @ Saint-Malo, France

* University of California, Berkeley + Samsung Research America

This project started during a summer internship of the first author at Samsung Research America in 2013 and 2014.

Page 2: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Why JavaScript? Popular

2

Page 3: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015 3

Portable Web/Server-side/Desktop Apps

Page 4: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Dynamic Yet Fast: JIT

4

• Resolve expensive dynamic features at runtime:

• E.g. Property access

• x.foo, x[“foo”], x[“fo”+”o”]

• Objects are hash tables (+ prototype)

• Optimized via inline-caching (with runtime-

type analysis)

Page 5: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

JIT Not Suitable for Small Devices

5

Page 6: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

JIT Not Suitable for Small Devices

6

• JIT compilers are memory hungry / draining energy.

• May quickly exhaust resources from small devices …

Page 7: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

• Ahead-of-time (AOT) compilation

- provides a similar performance

- without the cost of resource hungry JIT.

• Requirements:

- static type system

- with fixed-object layout property.

AOT instead of JIT

7

Page 8: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

• Statically compiled

• Statically typed (sound)

• Portable (subset of JavaScript)

• High-level features

• Light-weighted Annotation

SJS: Lightweight JavaScript

8

Requirements

Page 9: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

• Statically compiled

• Statically typed (sound)

• Portable (subset of JavaScript)

• High-level features

• Light-weighted Annotation

SJS: Lightweight JavaScript

9

asm.js

Existing systemsRequirements

Page 10: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

• Statically compiled

• Statically typed (sound)

• Portable (subset of JavaScript)

• High-level features

• Light-weighted Annotation

SJS: Lightweight JavaScript

10

asm.js TypeScript

Existing systemsRequirements

Page 11: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

• Statically compiled

• Statically typed (sound)

• Portable (subset of JavaScript)

• High-level features

• Light-weighted Annotation

SJS: Lightweight JavaScript

11

asm.js TypeScript

Existing systemsRequirements

SJS

Our System

Page 12: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

• Statically compiled

• Statically typed (sound)

• Portable (subset of JavaScript)

• High-level features

• Light-weighted Annotation

SJS: Lightweight JavaScript

12

asm.js TypeScript

Existing systemsRequirements

SJS

Our System

Why no static compilation? It does not guarantee fixed-object layout!

Page 13: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Fixed Object Layout ?

13

- Standard record type system is not useful for JavaScript.

- Three main challenges:

1. Prototyping

2. Methods

3. Subtyping

Page 14: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #1: Prototype

14

//  o1:  {  a:  Int  }  var  o1  =  {  a:  1  };  //  o2:  {  a:  Int,  b:Int  }  var  o2  =  {  b:  1,  __proto__:  o1  };  

print(o2.a);  o2.a  =  3;

a:1o1

Example

Page 15: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #1: Prototype

15

//  o1:  {  a:  Int  }  var  o1  =  {  a:  1  };  //  o2:  {  a:  Int,  b:Int  }  var  o2  =  {  b:  1,  __proto__:  o1  };  

a:1

b:1

o1

o2

An object can have a prototype object.

Example

Page 16: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

//  o1:  {  a:  Int  }  var  o1  =  {  a:  1  };  //  o2:  {  a:  Int,  b:Int  }  var  o2  =  {  b:  1,  __proto__:  o1  };  

print(o2.a);  

16

A failed read is delegated to the prototype.

a:1

b:1

Challenge #1: Prototype

o1

o2

Example

Page 17: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

//  o1:  {  a:  Int  }  var  o1  =  {  a:  1  };  //  o2:  {  a:  Int,  b:Int  }  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.a  =  3;

17

A write operation can adds an attribute even the attribute exist!

a:1

b:1 a:3

Challenge #1: Prototype

o1

o2

Example

Page 18: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

//  o1:  {  a:  Int  }  var  o1  =  {  a:  1  };  //  o2:  {  a:  Int,  b:Int  }  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.a  =  3;

18

a:1

b:1 a:3

Challenge #1: Prototype

A write operation can adds an attribute even the attribute exist!

Layout has changed !! Bad for AOT compilation.

o1

o2

Example

Page 19: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #1: Prototype

19

• Type system tracks the ownership of attributes

• For update operations, an attribute ownership is checked.

Solution: attribute ownership

//o1:  {  a:  Int  }  var  o1  =  {  a:  1  };  //o2:  {  a:  Int,  b:Int  }  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.a  =  3;

Attribute Ownership

Page 20: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #1: Prototype

20

• Type system tracks the ownership of attributes

• For update operations, an attribute ownership is checked.

Solution: attribute ownership

//o1:  {  a:  Int  },  own  =  {a}  var  o1  =  {  a:  1  };  //o2:  {  a:  Int,  b:Int  }  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.a  =  3;

Attribute Ownership

Page 21: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #1: Prototype

21

• Type system tracks the ownership of attributes

• For update operations, an attribute ownership is checked.

Solution: attribute ownership

//o1:  {  a:  Int  },  own  =  {a}  var  o1  =  {  a:  1  };  //o2:  {  a:  Int,  b:Int  },  own  =  {b}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.a  =  3;

Attribute Ownership

Page 22: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

//o1:  {  a:  Int  },  own  =  {a}  var  o1  =  {  a:  1  };  //o2:  {  a:  Int,  b:Int  },  own  =  {b}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.a  =  3;

Challenge #1: Prototype

22

• Type system tracks the ownership of attributes

• For update operations, attribute ownership is checked.

Solution: attribute ownership

Type Error !! a is not owned by o2

Attribute Ownership

Page 23: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

//o1:  {  a:  Int  },  own  =  {a}  var  o1  =  {  a:  1  };  //o2:  {  a:  Int,  b:Int  },  own  =  {b}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.a  =  3;

Challenge #1: Prototype

23

• Type system tracks the ownership of attributes

• For update operations, attribute ownership is checked.

Solution: attribute ownership

Type Error !! a is not owned by o2

Attribute Ownership

Page 24: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

function  Foo  (x)  {  this.a  =  2  }  

//  o1:  {  a:  Int,  f:  Int=>Undef  }                  //  own  =  {a,  f}  var  o1  =  {  a:  1,    f:  Foo  };  

Challenge #2: Method

24

a: 1 f: Fooo1

Example

Page 25: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

function  Foo  (x)  {  this.a  =  2  }  

//  o1:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f}  var  o1  =  {  a:  1,    f:  Foo  };  

//  o2:  {  a:  Int,  b:  Int,  f:  Int=>Undef  }  //  own  =  {b}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.f();

Challenge #2: Method

25

a: 1 f: Foo

b:1

o1

o2

Example

Page 26: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

function  Foo  (x)  {  this.a  =  2  }  

//  o1:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f}  var  o1  =  {  a:  1,    f:  Foo  };  

//  o2:  {  a:  Int,  b:  Int,  f:  Int=>Undef  }  //  own  =  {b}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.f();

Challenge #2: Method

26

a: 1 f: Foo

b:1

o1

o2

Example

Page 27: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

function  Foo  (x)  {  this.a  =  2  }  

//  o1:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f}  var  o1  =  {  a:  1,    f:  Foo  };  

//  o2:  {  a:  Int,  b:  Int,  f:  Int=>Undef  }  //  own  =  {b}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.f();

Challenge #2: Method

27

a: 1 f: Foo

b:1 a: 2

o1

o2

A method call can update an attribute (and layout)

Example

Page 28: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

function  Foo  (x)  {  this.a  =  2  }  

//  o1:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f}  var  o1  =  {  a:  1,    f:  Foo  };  

//  o2:  {  a:  Int,  b:  Int,  f:  Int=>Undef  }  //  own  =  {b}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.f();

Challenge #2: Method

28

a: 1 f: Foo

b:1 a: 2

A method call can update an attribute (and layout)

No information about f(). Ownership is not enough!

o1

o2

Example

Page 29: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

function  Foo  (x)  {  this.a  =  2  }  

//  o1:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f}  var  o1  =  {  a:  1,    f:  Foo  };  

//  o2:  {  a:  Int,  b:  Int,  f:  Int=>Undef  }  //  own  =  {b},  iown  =  {}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.f();

29

Challenge #2: Method

• Tracking attributes which should be owned by inheritors (iown).

Solution: inheritor-own attributes

Page 30: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

function  Foo  (x)  {  this.a  =  2  }  

//  o1:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f}  var  o1  =  {  a:  1,    f:  Foo  };  

//  o2:  {  a:  Int,  b:  Int,  f:  Int=>Undef  }  //  own  =  {b},  iown  =  {}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.f();

30

Challenge #2: Method

Inheritors should own it.

• Tracking attributes which should be owned by inheritors (iown).

Solution: inheritor-own attributes

Page 31: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

function  Foo  (x)  {  this.a  =  2  }  

//  o1:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},  iown  =  {a}  var  o1  =  {  a:  1,    f:  Foo  };  

//  o2:  {  a:  Int,  b:  Int,  f:  Int=>Undef  }  //  own  =  {b},  iown  =  {}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.f();

31

Challenge #2: Method

• Tracking attributes which should be owned by inheritors (iown).

Solution: inheritor-own attributes

Inheritors should own it.

Page 32: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

function  Foo  (x)  {  this.a  =  2  }  

//  o1:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},  iown  =  {a}  var  o1  =  {  a:  1,    f:  Foo  };  

//  o2:  {  a:  Int,  b:  Int,  f:  Int=>Undef  }  //  own  =  {b},  iown  =  {}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.f();

32

Challenge #2: Method

• Tracking attributes which should be owned by inheritors (iown).

• Inheriting objects should own them.

Solution: inheritor-own attributes

Inheritors should own it.

Page 33: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

function  Foo  (x)  {  this.a  =  2  }  

//  o1:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},  iown  =  {a}  var  o1  =  {  a:  1,    f:  Foo  };  

//  o2:  {  a:  Int,  b:  Int,  f:  Int=>Undef  }  //  own  =  {b},  iown  =  {}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.f();

33

Challenge #2: Method

• Tracking attributes which should be owned by inheritors (iown).

• Inheriting objects should own them.

Solution: inheritor-own attributes

Type Error !! o2 does not own a

Inheritors should own it.

Page 34: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

function  Foo  (x)  {  this.a  =  2  }  

//  o1:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},  iown  =  {a}  var  o1  =  {  a:  1,    f:  Foo  };  

//  o2:  {  a:  Int,  b:  Int,  f:  Int=>Undef  }  //  own  =  {b},  iown  =  {}  var  o2  =  {  b:  1,  __proto__:  o1  };  

o2.f();

34

Challenge #2: Method

• Tracking attributes which should be owned by inheritors (iown).

• Inheriting objects should own them.

Solution: inheritor-own attributes

Type Error !! o2 does not own a

Inheritors should own it.

Page 35: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

35

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Und.  }  //  own  =  {a,  c,  f},    iown  =  {c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o5:  {  a:  Int,  f:  Int=>Und.  }  //  own  =  {a},  iown  =  {}  var  o5  =  {  a:  4,  __proto__:  o3  }  o5.f();

Subtyping and Prototyping do not play well together .

Example

Page 36: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

36

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

Subtyping and Prototyping do not play well together .

Example

Page 37: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

37

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o5:  {  a:  Int,  f:  Int=>Und.  }  //  own  =  {a},  iown  =  {}  var  o5  =  {  a:  4,  __proto__:  o3  }  o5.f();

Subtyping and Prototyping do not play well together .

Example

Page 38: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

38

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o5:  {  a:  Int,  f:  Int=>Und.  }  //  own  =  {a},  iown  =  {}  var  o5  =  {  a:  4,  __proto__:  o3  }  o5.f();

Subtyping and Prototyping do not play well together .

o4 looks like a subtype of o3

Example

Page 39: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

39

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o5:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a},  iown  =  {}  var  o5  =  {  a:  4,  __proto__:  o3  }  o5.f();

Subtyping and Prototyping do not play well together .

Example

Page 40: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

40

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o5:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a},  iown  =  {}  var  o5  =  {  a:  4,  __proto__:  o3  }  o5.f();

Subtyping and Prototyping do not play well together .

o5 owns a, which is required to inherit o3.

Example

Page 41: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

41

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o5:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a},  iown  =  {}  var  o5  =  {  a:  4,  __proto__:  o3  }  o5.f();

Subtyping and Prototyping do not play well together .

Example

Page 42: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

42

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o5:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a},  iown  =  {}  var  o5  =  {  a:  4,  __proto__:  o3  }  o5.f();

Subtyping and Prototyping do not play well together .

invoke o4.f()

Example

Page 43: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

43

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o5:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a},  iown  =  {}  var  o5  =  {  a:  4,  __proto__:  o3  }  o5.f();

Layout will change!!

invoke o4.f()

Subtyping and Prototyping do not play well together .

Example

Page 44: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

44

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

a,a

Subtyping and Prototyping do not play well together .

Source of the problem

Page 45: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

45

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o5:  {  a:  Int,  f:  Int=>Und.  }  //  own  =  {a},  iown  =  {}  var  o5  =  {  a:  4,  __proto__:  o3  }  o5.f();

Subtyping and Prototyping do not play well together .

Source of the problem

iown is overshadowed.

Page 46: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

46

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o5:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a},  iown  =  {}  var  o5  =  {  a:  4,  __proto__:  o3  }  o5.f();

Subtyping and Prototyping do not play well together .

Source of the problem

Checking with imprecise iown

Page 47: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

47

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o5:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a},  iown  =  {}  var  o5  =  {  a:  4,  __proto__:  o3  }  o5.f();

Subtyping and Prototyping do not play well together .

Source of the problem

iown should be precise for prototyping

Checking with imprecise iown

Page 48: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

48

//  o3:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a,  f},    iown  =  {a}  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  

//  o4:  {  a:  Int,  c:Int,  f:  Int=>Undef  }  //  own  =  {a,  c,  f},    iown  =  {a,  c}  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o5:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a},  iown  =  {}  var  o5  =  {  a:  4,  __proto__:  o3  }  o5.f();

Subtyping and Prototyping do not play well together .

Source of the problem

iown should be precise for prototyping

Checking with imprecise iown

To subtype or not to subtype …

Page 49: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

• Operations - Prototyping for precise types - Subtyping for approximate types

• Creation - A new object has a precise type.

• Casting - A precise type can be downcast to an approximate type.

Challenge #3: Subtyping

49

Solution: Precise and Approximate objects

Page 50: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

50

//  o3  and  o4  are  precise  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o6:  approx.  {  a:  Int,  f:  Int=>Und.  }      //  own  =  {a}  var  o6  =  (random()  ==  0)  ?  o3  :  o4    o6.a  =  1  o6.f()  

//  o7:  {  a:  Int,  f:  Int=>Und.  }  //  own  =  {a},  iown  =  {}  var  o7  =  {  a:  4,  __proto__:  o6  }

Solution: Precise and Approximate objects

Page 51: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

51

//  o3  and  o4  are  precise  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o6:  approx.  {  a:  Int,  f:  Int=>Und.  }      //  own  =  {a}  var  o6  =  (random()  ==  0)  ?  o3  :  o4    o6.a  =  1  o6.f()  

//  o7:  {  a:  Int,  f:  Int=>Und.  }  //  own  =  {a},  iown  =  {}  var  o7  =  {  a:  4,  __proto__:  o6  }

Solution: Precise and Approximate objects

Page 52: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

52

//  o3  and  o4  are  precise  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o6:  approx.  {  a:  Int,  f:  Int=>Und.  }      //  own  =  {a}  var  o6  =  (random()  ==  0)  ?  o3  :  o4    o6.a  =  1  o6.f()  

//  o7:  {  a:  Int,  f:  Int=>Und.  }  //  own  =  {a},  iown  =  {}  var  o7  =  {  a:  4,  __proto__:  o6  }

Solution: Precise and Approximate objects

Error !! No subtyping on precise types

Page 53: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

53

//  o3  and  o4  are  precise  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o6:  approx.  {  a:  Int,  f:  Int=>Undef  }    //  own  =  {a}  var  o6  =  (*)  ?  o3  :  o4    o6.a  =  1  o6.f()  

//  o7:  {  a:  Int,  f:  Int=>Und.  }  //  own  =  {a},  iown  =  {}  var  o7  =  {  a:  4,  __proto__:  o6  }

Solution: Precise and Approximate objects

Error !! No subtyping on precise types

Page 54: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

54

//  o3  and  o4  are  precise  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o6:  approx.  {  a:  Int,  f:  Int=>Undef  }    //  own  =  {a}  var  o6  =  (*)  ?  o3  :  o4    o6.a  =  1  o6.f()  

//  o7:  {  a:  Int,  f:  Int=>Und.  }  //  own  =  {a},  iown  =  {}  var  o7  =  {  a:  4,  __proto__:  o6  }

Solution: Precise and Approximate objects

Error !! No subtyping on precise types

Safe: Downcasting (implicit)

Page 55: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

55

//  o3  and  o4  are  precise  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o6:  approx.  {  a:  Int,  f:  Int=>Undef  }    //  own  =  {a}  var  o6  =  (*)  ?  o3  :  o4    o6.a  =  1  o6.f()  

//  o7:  {  a:  Int,  f:  Int=>Und.  }  //  own  =  {a},  iown  =  {}  var  o7  =  {  a:  4,  __proto__:  o6  }

Solution: Precise and Approximate objects

Error !! No subtyping on precise types

Safe: Updates and method

calls are allowed.

Safe: Downcasting (implicit)

Page 56: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

56

//  o3  and  o4  are  precise  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o6:  approx.  {  a:  Int,  f:  Int=>Undef  }    //  own  =  {a}  var  o6  =  (*)  ?  o3  :  o4    o6.a  =  1  o6.f()  

//  o7:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a},  iown  =  {}  var  o7  =  {  a:  4,  __proto__:  o6  }

Solution: Precise and Approximate objects

Error !! No subtyping on precise types

Safe: Updates and method

calls are allowed.

Safe: Downcasting (implicit)

Page 57: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Challenge #3: Subtyping

57

//  o3  and  o4  are  precise  var  o3  =  {  a:  1,  f:  fun(x){this.a  =  2}  }  var  o4  =  {  a:  2,  c:  3,                        f:  fun(x){this.c  =  4}  }  

o3  =  o4  

//  o6:  approx.  {  a:  Int,  f:  Int=>Undef  }    //  own  =  {a}  var  o6  =  (*)  ?  o3  :  o4    o6.a  =  1  o6.f()  

//  o7:  {  a:  Int,  f:  Int=>Undef  }  //  own  =  {a},  iown  =  {}  var  o7  =  {  a:  4,  __proto__:  o6  }

Solution: Precise and Approximate objects

Error !! No subtyping on precise types

Safe: Updates and method

calls are allowed.

Error: No prototyping on approximate types.

Safe: Downcasting (implicit)

Page 58: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

• Formally defined core calculus

- Static and dynamic semantics.

- Objects, high-order functions, method updates, first-class method value, prototyping, and subtyping.

• Fixed object layout theorem

- A well-typed program never modifies object layouts after object construction.

• Corollary

- A well-typed programs can be compiled ahead-of-time.

Theoretic Result

58

Page 59: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

• Type inference engine + Compiler (to C).

- Type inference requires annotations for base types.

- Qualifiers (iown, own, etc.) are automatically inferred.

- The resulting C program is compiled with the Boehm garbage-collector using Clang.

Evaluation: Implementation

59

Page 60: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

• Benchmarks

- 2 web apps

- 2 octane benchmarks

- 500-2000 lines of code

• Results

- 1 type annotation / 8.34 lines of code.

- 86% of annotations are for function parameters.

Evaluation: Usability

60

Page 61: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Evaluation: Performance

61

• A performance compatible with node.js • Without using a resource hungry JIT!

*smaller is better

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

Page 62: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Evaluation: Performance

62

• A performance compatible with node.js • Without using a resource hungry JIT!

*smaller is better

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"0"

50"

100"

150"

200"

250"

300"

350"

400"

bdd" bh

"

huffman"

mandel"

matmul" ray

"

simplex"

spectral:norm

"

tsp:ga"

Normalized

+Execu0o

n+Time+(%

)+

Benchmarks+

SJS+Performance+(vs+V8)+

Total"Execu?on"Time"

without"GC"

Page 63: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Summary

63

AOTC of JavaScript is doable witha type system guaranteeing fixed object layout.

Conclusion

Page 64: A Type System for JavaScript with Fixed Object LayoutWontae Choi @ Static Analysis Symposium 2015 • Ahead-of-time (AOT) compilation -provides a similar performance -without the cost

Wontae Choi @ Static Analysis Symposium 2015

Summary

64

AOTC of JavaScript is doable witha type system guaranteeing fixed object layout.

AOTC provides JIT like performancewithout the cost of JIT.

Conclusion