• Save
JSX Optimizer
Upcoming SlideShare
Loading in...5
×
 

JSX Optimizer

on

  • 4,179 views

 

Statistics

Views

Total Views
4,179
Views on SlideShare
4,164
Embed Views
15

Actions

Likes
8
Downloads
0
Comments
1

4 Embeds 15

http://us-w1.rockmelt.com 7
https://si0.twimg.com 6
https://twimg0-a.akamaihd.net 1
https://abs.twimg.com 1

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • The procedures for running the box2d.jsx benchmark is described at https://github.com/jsx/JSX/wiki/Benchmark-%28box2d.jsx%29
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

JSX Optimizer JSX Optimizer Presentation Transcript

  • JSX Optimizer DeNA Co., Ltd. Kazuho Oku
  • The Basic Idea of the JSX Optimizer perform optimizations that JavaScript VMs cannotJul 19 2012 JSX Optimizer 2
  • Benchmark Scores Box2D.jsx +13.5% (iOS 5.0, iPhone 4) +11.8% (iOS 5.1, iPhone 4S) +28.7% (Android 2.3, Xperia ray) numbers are increase in fps ToDo: post the detailsJul 19 2012 JSX Optimizer 3
  • The Nature of JavaScript a dynamic language primitives are untyped a + 1 becomes "a1" if a is "a", 2 if a is 1 objects are untyped a.p may point to whatever solution: inline caching V8, JavaScriptCore, SpiderMonkeyJul 19 2012 JSX Optimizer 4
  • Inline Caching The idea: most of the code will be called with the same types of arguments cache the expectation at the call site Example: point.x type of point will be { x: ?, y: ? } thus if the expectation succeeded, point.x will be: load point_addr[offset_of_x]Jul 19 2012 JSX Optimizer 5
  • Guards in Inline Caching Example: a = b.p + 1 typeof(b) is as expected load b.p typeof(b.p) is number add one store the resultJul 19 2012 JSX Optimizer 6
  • Guards in Inline Caching (contd) Example: f() typeof(f) is function setup stack frame jump to the code of fJul 19 2012 JSX Optimizer 7
  • Guards in Inline Caching (contd) Example: f() // after inlined typeof(f) is function  f has not been altered execute the code expanded in-lineJul 19 2012 JSX Optimizer 8
  • Guards in Inline Caching (contd) Example: o.f() typeof(o) is as expected load o.prototype typeof (o.prototype) is as expected load o.prototype.f typeof(f) is function setup stack frame jump to the code of fJul 19 2012 JSX Optimizer 9
  • Guards in Inline Caching (contd) Example: o.f() // after inlined typeof(o) is as expected load o.prototype typeof (o.prototype) is as expected load o.prototype.f typeof(f) is function  f has not been altered execute the code expanded in-lineJul 19 2012 JSX Optimizer 10
  • What interpreters do / do not inter-statement optimization V8 does SpiderMonkey and JavaScriptCore seem not inline-expand the JavaScript functions at least V8 doesJul 19 2012 JSX Optimizer 11
  • JSX optimizer minimizes the need for IC caches property access JSX does not have accessors (Object.defineProperty) inline-expands the functions converts member methods to static functions generates IC-friendly code always initializes the properties in same order Note: { x: 0, y: 0 } and { y: 1, x: 1 } are different typesJul 19 2012 JSX Optimizer 12
  • JSX optimizer minimizes the pressure on GC unboxing folds constants JavaScript does not have a true constJul 19 2012 JSX Optimizer 13
  • Example: affine transformation input: new Matrix(1, 0, 0, 0, 2, 0).transform(new Point(x, y)) output: {x: x + 0 * y, y: 0 * x + 2 * y} Note: 0 * n cannot be optimized to 0, since it becomes NaN if n is NaNJul 19 2012 JSX Optimizer 14
  • Current Optimization Subcommands  lto  no-assert  no-log  unclassify  fold-const  inline  dce  return-if  lcse  unbox  array-lengthJul 19 2012 JSX Optimizer 15
  • Diffs. from an ordinary optimizing compiler ordinary compiler generate a low-level non-redundant code JSX compiler most code are left as is while optimizing the code wherever possibleJul 19 2012 JSX Optimizer 16
  • The Difficulties and Considerations switch to SSA-based code? might end-up in generating a very different code from source would be difficult to debug (by the users) may become slow (than the same-looking code in JavaScript); GCC has the problem it is troublesome to optimize the code while maintaining the original code structure example. support various kind of loops: do-while, for, for..in, whileJul 19 2012 JSX Optimizer 17
  • The Difficulties and Considerations (contd) Other optimization techniques? inline allocation? more powerful dce / dse reduce the number of locals?Jul 19 2012 JSX Optimizer 18
  • Some Microbenchmarks http://jsperf.com/local-vs-member/2 http://jsperf.com/construct-object-vs-array/3 http://jsperf.com/inherit-object-vs-array-set http://jsperf.com/vars-in-nested-closureJul 19 2012 JSX Optimizer 19