JSX Optimizer    DeNA Co., Ltd.     Kazuho Oku
The Basic Idea of the JSX Optimizer    perform optimizations that JavaScript VMs                     cannotJul 19 2012    ...
Benchmark Scores   Box2D.jsx         +13.5% (iOS 5.0, iPhone 4)         +11.8% (iOS 5.1, iPhone 4S)         +28.7% (An...
The Nature of JavaScript   a dynamic language         primitives are untyped              a + 1 becomes "a1" if a is "a...
Inline Caching   The idea:         most of the code will be called with the same          types of arguments         ca...
Guards in Inline Caching   Example: a = b.p + 1         typeof(b) is as expected         load b.p         typeof(b.p) ...
Guards in Inline Caching (contd)   Example: f()         typeof(f) is function         setup stack frame         jump t...
Guards in Inline Caching (contd)   Example: f() // after inlined         typeof(f) is function          f has not been ...
Guards in Inline Caching (contd)   Example: o.f()         typeof(o) is as expected         load o.prototype         ty...
Guards in Inline Caching (contd)   Example: o.f() // after inlined         typeof(o) is as expected         load o.prot...
What interpreters do / do not   inter-statement optimization         V8 does         SpiderMonkey and JavaScriptCore se...
JSX optimizer   minimizes the need for IC         caches property access              JSX does not have accessors (Obje...
JSX optimizer   minimizes the pressure on GC         unboxing   folds constants         JavaScript does not have a tru...
Example: affine transformation   input:         new Matrix(1, 0, 0, 0, 2, 0).transform(new Point(x, y))   output:       ...
Current Optimization Subcommands      lto      no-assert      no-log      unclassify      fold-const      inline   ...
Diffs. from an ordinary optimizing compiler   ordinary compiler         generate a low-level non-redundant code   JSX c...
The Difficulties and Considerations   switch to SSA-based code?         might end-up in generating a very different code...
The Difficulties and Considerations (contd)   Other optimization techniques?         inline allocation?         more po...
Some Microbenchmarks   http://jsperf.com/local-vs-member/2   http://jsperf.com/construct-object-vs-array/3   http://jsperf...
Upcoming SlideShare
Loading in...5
×

JSX Optimizer

4,609

Published on

Published in: Technology, Art & Photos
1 Comment
8 Likes
Statistics
Notes
  • The procedures for running the box2d.jsx benchmark is described at https://github.com/jsx/JSX/wiki/Benchmark-%28box2d.jsx%29
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
4,609
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
1
Likes
8
Embeds 0
No embeds

No notes for slide

JSX Optimizer

  1. 1. JSX Optimizer DeNA Co., Ltd. Kazuho Oku
  2. 2. The Basic Idea of the JSX Optimizer perform optimizations that JavaScript VMs cannotJul 19 2012 JSX Optimizer 2
  3. 3. 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
  4. 4. 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
  5. 5. 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
  6. 6. 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
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. 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
  11. 11. 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
  12. 12. 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
  13. 13. JSX optimizer minimizes the pressure on GC unboxing folds constants JavaScript does not have a true constJul 19 2012 JSX Optimizer 13
  14. 14. 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
  15. 15. Current Optimization Subcommands  lto  no-assert  no-log  unclassify  fold-const  inline  dce  return-if  lcse  unbox  array-lengthJul 19 2012 JSX Optimizer 15
  16. 16. 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
  17. 17. 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
  18. 18. 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
  19. 19. 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

×