SlideShare une entreprise Scribd logo
1  sur  59
Untyped Compilation


function f(left, right) {
  var t = left + right
  ...
}
Untyped Compilation
                            Compile Everything!


function f(left, right) {
  var t = left + right
  ...
}
Untyped Compilation
                            Compile Everything!
                  ... but only one type at a time.
function f(left, right) {
  var t = left + right
  ...
}
Let’s Compile Numbers
                   JavaScript numbers are floats


function f(left, right) {
  var t = left + right
  ...
}

f(5, 10);
Let’s Compile Numbers
                   JavaScript numbers are floats
                  ... but we can use integers, too
function f(left, right) {
  var t = left + right
  ...
}

f(5, 10);
Integer Add
     Register   Variable

       edi      left.type


      eax       left.data


      ebx       right.type


      edx       right.data
Integer Add
                    Register   Variable

                      edi      left.type


                     eax       left.data

add edx, eax         ebx       right.type


                     edx       right.data
Register   Variable      Value

                 edi      left.type    STRING

                eax       left.data     “a”

add edx, eax    ebx       right.type   INT32

                edx       right.data     35
Oh no, a string
                      Register   Variable      Value

                        edi      left.type    STRING

                       eax       left.data     “a”

add edx, eax           ebx       right.type   INT32

                       edx       right.data     35
Oh no, a string
                                  Register   Variable      Value

                                    edi      left.type    STRING

          Integer add is bogus!    eax       left.data     “a”

add edx, eax                       ebx       right.type   INT32

                                   edx       right.data     35
Integers, Untyped JIT
                      Register   Variable

                        edi      left.type
cmp edi, 0xffffff81
jne other              eax       left.data
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type


                       edx       right.data
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data    35
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data    35
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data    35
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data    35
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data    35
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data    35
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data    35
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data    35
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data    35
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data    35
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data    35
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data    35
Integers, Untyped JIT
                      Register   Variable     Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data     27
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx         t.type
                                 right.type   INT32

                       edx         t.data
                                 right.data    62
                                               35
What about...
                 Calling f() with a huge integer?


function f(left, right) {
  var t = left + right
  ...
}

f(2147483647, 2147483647);
Integers, Untyped JIT
                      Register   Variable      Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data    2^31-1
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data   2^31-1
Integers, Untyped JIT
                      Register   Variable      Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data    2^31-1
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32

                       edx       right.data   2^31-1
Integers, Untyped JIT
                      Register   Variable      Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data    2^31-1
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx         t.type
                                 right.type   INT32

                       edx         t.data
                                 right.data     -2
                                              2^31-1
JavaScript Numbers


js> 2147483647 + 2147483647
JavaScript Numbers


js> 2147483647 + 2147483647 ↵
4294967294
JavaScript Numbers


js> 2147483647 + 2147483647
4294967294
js> 4294967294 == -2
JavaScript Numbers


js> 2147483647 + 2147483647
4294967294
js> 4294967294 == -2 ↵
false
Integers, Untyped JIT
                      Register   Variable      Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data    2^31-1
cmp ebx, 0xffffff81
jne other
add edx, eax           ebx       right.type   INT32
jo stub

                       edx       right.data   2^31-1
Integers, Untyped JIT
                      Register   Variable      Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data    2^31-1
cmp ebx, 0xffffff81
jne other
add edx, eax
jo stub
                       ebx         t.type
                                 right.type   INT32

                       edx         t.data
                                 right.data     -2
                                              2^31-1
Integers, Untyped JIT
                      Register   Variable      Value

                        edi      left.type    INT32
cmp edi, 0xffffff81
jne other              eax       left.data    2^31-1
cmp ebx, 0xffffff81
jne other
add edx, eax
jo stub
                       ebx         t.type
                                 right.type   INT32

                       edx         t.data
                                 right.data     -2
                                              2^31-1
Hey! What about
                   floats?

function f(left, right) {
  var t = left + right
  ...
}

f(2.717, Math.PI);
Floats, Untyped JIT

cmp edi, 0xffffff81
jne other
cmp ebx, 0xffffff81
jne other
add edx, eax
jo stub
Floats, Untyped JIT
                          cmp edi, 0xffffff80
                          jae stub
                          cmp edi, 0xffffff80
                          jb skip_convert
                          cmp ebx, 0xffffff81
                          jne stub
cmp edi, 0xffffff81       cvtsi2sd xmm5, eax
jne other                 jmp converted
cmp ebx, 0xffffff81      skip_convert:
                          movd xmm5, eax
jne other                 pinsrd xmm5, ebx, 1
add edx, eax             converted:
jo stub                   movd xmm6, edx
                          pinsrd xmm6, edi, 1
                          jmp add
Floats, Untyped JIT
                          cmp edi, 0xffffff80
                          jae stub
                          cmp edi, 0xffffff80
                          jb skip_convert
                          cmp ebx, 0xffffff81
                          jne stub
cmp edi, 0xffffff81       cvtsi2sd xmm5, eax
jne other                 jmp converted
cmp ebx, 0xffffff81      skip_convert:
                          movd xmm5, eax
jne other                 pinsrd xmm5, ebx, 1
add edx, eax             converted:
jo stub                   movd xmm6, edx
                          pinsrd xmm6, edi, 1
                          jmp add

                         cmp ebx, 0xffffff80
                         jae stub
                         cvtsi2sd xmm6, ecx
                         movd xmm5, eax
                         pinsrd xmm5, ebx, 1
                         jmp add
Floats, Untyped JIT
                                     cmp edi, 0xffffff80
                                     jae stub
                                     cmp edi, 0xffffff80
                                     jb skip_convert
                                     cmp ebx, 0xffffff81
                                     jne stub
cmp edi, 0xffffff81                  cvtsi2sd xmm5, eax
jne other                            jmp converted
cmp ebx, 0xffffff81                 skip_convert:
                                     movd xmm5, eax
jne other                            pinsrd xmm5, ebx, 1
add edx, eax                        converted:
jo stub                              movd xmm6, edx
                                     pinsrd xmm6, edi, 1
                                     jmp add

                                    cmp ebx, 0xffffff80
                                    jae stub
                                    cvtsi2sd xmm6, ecx
                                    movd xmm5, eax
          add:                      pinsrd xmm5, ebx, 1
           addsd xmm6, xmm5         jmp add
           movsd [ebp+0x50], xmm6
           movl edx, [ebp+0x50]
           jmp rejoin
Floats, Untyped JIT
                                     cmp edi, 0xffffff80
                                     jae stub
                                     cmp edi, 0xffffff80
                                     jb skip_convert
                                     cmp ebx, 0xffffff81
                                     jne stub
cmp edi, 0xffffff81                  cvtsi2sd xmm5, eax
jne other                            jmp converted
cmp ebx, 0xffffff81                 skip_convert:
                                     movd xmm5, eax
jne other                            pinsrd xmm5, ebx, 1
add edx, eax                        converted:
jo stub                              movd xmm6, edx
                                     pinsrd xmm6, edi, 1
                                     jmp add

                                    cmp ebx, 0xffffff80
                                    jae stub
                                    cvtsi2sd xmm6, ecx
                                    movd xmm5, eax
          add:                      pinsrd xmm5, ebx, 1
           addsd xmm6, xmm5         jmp add
           movsd [ebp+0x50], xmm6
           movl edx, [ebp+0x50]
           jmp rejoin                   30 instructions!
Benchmark...
Benchmark...



function distance(a, b) {
  var t;
  for (var i = 0; i < a; i++) {
     for (var j = 0; j < b; j++) {
         t = ((a - i) * (a - i)) +
            ((b - j) * (b - j));
     }
  }
}
The Whole Loop

                                                    cmp    $0xffffff81,%ebx
                                                    jne    0xf73ef58f

                                                       (b - j)
cmp    $0xffffff81,%edi                             cmp    $0xffffff81,%edx
jne    0xf73ef353

    (a - i)
                                                    jne    0xf73ef5cc
cmp    $0xffffff81,%esi   cmp    $0xffffff81,%edx   sub    %esi,%eax          cmp    $0xffffff81,%edx
jne    0xf73ef390         jne    0xf73ef4ce         jo     0xf73ef5f4         jne    0xf73ef72b         cmp    $0xffffff81,%edi
sub    %edx,%ecx          cmp    $0xffffff81,%ebx                             cmp    $0xffffff81,%ebx   jne    0xf73ef7f5
jo     0xf73ef3b8
                                      *
                          jne    0xf73ef50b
                          imul   %eax,%ecx
                          jo     0xf73ef550
                                                                                          *
                                                                              jne    0xf73ef768
                                                                              imul   %edi,%eax
                                                                              jo     0xf73ef7b0
                                                                                                                    +
                                                                                                        cmp    $0xffffff81,%ebx
                                                                                                        jne    0xf73ef832
                                                                                                        add    %eax,%edx
cmp    $0xffffff81,%edi   test   %ecx,%ecx          cmp    $0xffffff81,%ebx   test   %eax,%eax          jo     0xf73ef85a
jne    0xf73ef40c         je     0xf73ef533         jne    0xf73ef65a         je     0xf73ef790


    (a - i)
cmp    $0xffffff81,%esi
jne    0xf73ef449
sub    %edx,%eax
                                                       (b - j)
                                                    cmp    $0xffffff81,%edx
                                                    jne    0xf73ef697
                                                    sub    %esi,%edi
jo     0xf73ef471                                   jo     0xf73ef6bf
The Whole Loop
                                              ~230 instructions

                                                    cmp    $0xffffff81,%ebx
                                                    jne    0xf73ef58f

                                                       (b - j)
cmp    $0xffffff81,%edi                             cmp    $0xffffff81,%edx
jne    0xf73ef353

    (a - i)
                                                    jne    0xf73ef5cc
cmp    $0xffffff81,%esi   cmp    $0xffffff81,%edx   sub    %esi,%eax          cmp    $0xffffff81,%edx
jne    0xf73ef390         jne    0xf73ef4ce         jo     0xf73ef5f4         jne    0xf73ef72b         cmp    $0xffffff81,%edi
sub    %edx,%ecx          cmp    $0xffffff81,%ebx                             cmp    $0xffffff81,%ebx   jne    0xf73ef7f5
jo     0xf73ef3b8
                                      *
                          jne    0xf73ef50b
                          imul   %eax,%ecx
                          jo     0xf73ef550
                                                                                          *
                                                                              jne    0xf73ef768
                                                                              imul   %edi,%eax
                                                                              jo     0xf73ef7b0
                                                                                                                    +
                                                                                                        cmp    $0xffffff81,%ebx
                                                                                                        jne    0xf73ef832
                                                                                                        add    %eax,%edx
cmp    $0xffffff81,%edi   test   %ecx,%ecx          cmp    $0xffffff81,%ebx   test   %eax,%eax          jo     0xf73ef85a
jne    0xf73ef40c         je     0xf73ef533         jne    0xf73ef65a         je     0xf73ef790


    (a - i)
cmp    $0xffffff81,%esi
jne    0xf73ef449
sub    %edx,%eax
                                                       (b - j)
                                                    cmp    $0xffffff81,%edx
                                                    jne    0xf73ef697
                                                    sub    %esi,%edi
jo     0xf73ef471                                   jo     0xf73ef6bf
The Whole Loop
                                              ~230 instructions

                                                    cmp    $0xffffff81,%ebx
                                                    jne    0xf73ef58f

                                                       (b - j)
cmp    $0xffffff81,%edi                             cmp    $0xffffff81,%edx
jne    0xf73ef353

    (a - i)
                                                    jne    0xf73ef5cc
cmp    $0xffffff81,%esi   cmp    $0xffffff81,%edx   sub    %esi,%eax          cmp    $0xffffff81,%edx
jne    0xf73ef390         jne    0xf73ef4ce         jo     0xf73ef5f4         jne    0xf73ef72b         cmp    $0xffffff81,%edi
sub    %edx,%ecx          cmp    $0xffffff81,%ebx                             cmp    $0xffffff81,%ebx   jne    0xf73ef7f5
jo     0xf73ef3b8
                                      *
                          jne    0xf73ef50b
                          imul   %eax,%ecx
                          jo     0xf73ef550
                                                                                          *
                                                                              jne    0xf73ef768
                                                                              imul   %edi,%eax
                                                                              jo     0xf73ef7b0
                                                                                                                    +
                                                                                                        cmp    $0xffffff81,%ebx
                                                                                                        jne    0xf73ef832
                                                                                                        add    %eax,%edx
cmp    $0xffffff81,%edi   test   %ecx,%ecx          cmp    $0xffffff81,%ebx   test   %eax,%eax          jo     0xf73ef85a
jne    0xf73ef40c         je     0xf73ef533         jne    0xf73ef65a         je     0xf73ef790


    (a - i)
cmp    $0xffffff81,%esi
jne    0xf73ef449
sub    %edx,%eax
                                                       (b - j)
                                                    cmp    $0xffffff81,%edx
                                                    jne    0xf73ef697
                                                    sub    %esi,%edi
jo     0xf73ef471                                   jo     0xf73ef6bf




                                       JägerMonkey runs 100mil
                                         iterations in 1012ms
Can we do better?

function distance(a, b) {
  var t;
  for (var i = 0; i < a; i++) {
     for (var j = 0; j < b; j++) {
         t = ((a - i) * (a - i)) +
            ((b - j) * (b - j));
     }
  }
}
Typed Optimizations

function distance(a, b) {
  var t;
  for (var i = 0; i < a; i++) {
     for (var j = 0; j < b; j++) {
         t = ((a - i) * (a - i)) +
            ((b - j) * (b - j));
     }
  }
}
Hoisting
                                         Move computation
                                         outside of the loop
function distance(a, b) {
  var t;
  for (var i = 0; i < a; i++) {
     var t0 = ((a - i) * (a - i));
     for (var j = 0; j < b; j++) {
         t = t0 + ((b - j) * (b - j));
     }
  }
}
Why only Typed JITs?

var ham = 0;

var obj = { valueOf: function () {
           return ham++;
        }
      }


f(obj, obj);
Why only Typed JITs?
                                     “ham” must be incremented
var ham = 0;

var obj = { valueOf: function () {
           return ham++;
        }
      }


f(obj, obj);
Typed Optimization

function distance(a, b) {
  var t;
  for (var i = 0; i < a; i++) {
     var t0 = ((a - i) * (a - i));
     for (var j = 0; j < b; j++) {
         t = t0 + ((b - j) * (b - j));
     }
  }
}
Elimination
                                     Redundant (b - j)
function distance(a, b) {               eliminated
  var t;
  for (var i = 0; i < a; i++) {
     var t0 = ((a - i) * (a - i));
     for (var j = 0; j < b; j++) {
         var temp = (b - j);
         t = t0 + (temp * temp);
     }
  }
}
Typed JIT - IonMonkey
  sub    eax, ecx       ; t0 = (b - j)
  jo     0xf73ed01d
  imul   eax, eax       ; t1 = (t0 * t0)
  jo     0xf73ed022
  test   eax, eax
  je     0xf73ed022
  add    ebx, eax       ; t2 = (expr) + t1
  jo     0xf73ed027
Typed JIT - IonMonkey
  sub    eax, ecx       ; t0 = (b - j)
  jo     0xf73ed01d
  imul   eax, eax       ; t1 = (t0 * t0)
  jo     0xf73ed022
  test   eax, eax
  je     0xf73ed022
  add    ebx, eax       ; t2 = (expr) + t1
  jo     0xf73ed027




    Runs in 250ms, or 3.8X faster!
Smarter

sub    eax, ecx       ; t0 = (b - j)
jo     0xf73ed01d
imul   eax, eax       ; t1 = (t0 * t0)
jo     0xf73ed022
add    ebx, eax       ; t2 = (expr) + t1
jo     0xf73ed027




  Runs in 220ms, or 4.6X faster!
Arithmetic in C

movl ecx, ebx
subl ecx, ebx
imul ecx, ecx
addl ecx, esi
Arithmetic in C

movl ecx, ebx   •C: 97ms
subl ecx, ebx   •Untyped JIT within 10X
imul ecx, ecx   •Typed JIT within ~2X
addl ecx, esi
Semantic Gap
• No way to tell JS, “use integers”
• C distinguishes float/ints

Contenu connexe

Dernier

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 

Dernier (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

En vedette

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

En vedette (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

JS Math JITing - JSConf.eu

  • 1. Untyped Compilation function f(left, right) { var t = left + right ... }
  • 2. Untyped Compilation Compile Everything! function f(left, right) { var t = left + right ... }
  • 3. Untyped Compilation Compile Everything! ... but only one type at a time. function f(left, right) { var t = left + right ... }
  • 4. Let’s Compile Numbers JavaScript numbers are floats function f(left, right) { var t = left + right ... } f(5, 10);
  • 5. Let’s Compile Numbers JavaScript numbers are floats ... but we can use integers, too function f(left, right) { var t = left + right ... } f(5, 10);
  • 6. Integer Add Register Variable edi left.type eax left.data ebx right.type edx right.data
  • 7. Integer Add Register Variable edi left.type eax left.data add edx, eax ebx right.type edx right.data
  • 8. Register Variable Value edi left.type STRING eax left.data “a” add edx, eax ebx right.type INT32 edx right.data 35
  • 9. Oh no, a string Register Variable Value edi left.type STRING eax left.data “a” add edx, eax ebx right.type INT32 edx right.data 35
  • 10. Oh no, a string Register Variable Value edi left.type STRING Integer add is bogus! eax left.data “a” add edx, eax ebx right.type INT32 edx right.data 35
  • 11. Integers, Untyped JIT Register Variable edi left.type cmp edi, 0xffffff81 jne other eax left.data cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type edx right.data
  • 12. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 35
  • 13. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 35
  • 14. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 35
  • 15. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 35
  • 16. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 35
  • 17. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 35
  • 18. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 35
  • 19. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 35
  • 20. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 35
  • 21. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 35
  • 22. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 35
  • 23. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 35
  • 24. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 27 cmp ebx, 0xffffff81 jne other add edx, eax ebx t.type right.type INT32 edx t.data right.data 62 35
  • 25. What about... Calling f() with a huge integer? function f(left, right) { var t = left + right ... } f(2147483647, 2147483647);
  • 26. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 2^31-1 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 2^31-1
  • 27. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 2^31-1 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 edx right.data 2^31-1
  • 28. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 2^31-1 cmp ebx, 0xffffff81 jne other add edx, eax ebx t.type right.type INT32 edx t.data right.data -2 2^31-1
  • 30. JavaScript Numbers js> 2147483647 + 2147483647 ↵ 4294967294
  • 31. JavaScript Numbers js> 2147483647 + 2147483647 4294967294 js> 4294967294 == -2
  • 32. JavaScript Numbers js> 2147483647 + 2147483647 4294967294 js> 4294967294 == -2 ↵ false
  • 33. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 2^31-1 cmp ebx, 0xffffff81 jne other add edx, eax ebx right.type INT32 jo stub edx right.data 2^31-1
  • 34. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 2^31-1 cmp ebx, 0xffffff81 jne other add edx, eax jo stub ebx t.type right.type INT32 edx t.data right.data -2 2^31-1
  • 35. Integers, Untyped JIT Register Variable Value edi left.type INT32 cmp edi, 0xffffff81 jne other eax left.data 2^31-1 cmp ebx, 0xffffff81 jne other add edx, eax jo stub ebx t.type right.type INT32 edx t.data right.data -2 2^31-1
  • 36. Hey! What about floats? function f(left, right) { var t = left + right ... } f(2.717, Math.PI);
  • 37. Floats, Untyped JIT cmp edi, 0xffffff81 jne other cmp ebx, 0xffffff81 jne other add edx, eax jo stub
  • 38. Floats, Untyped JIT cmp edi, 0xffffff80 jae stub cmp edi, 0xffffff80 jb skip_convert cmp ebx, 0xffffff81 jne stub cmp edi, 0xffffff81 cvtsi2sd xmm5, eax jne other jmp converted cmp ebx, 0xffffff81 skip_convert: movd xmm5, eax jne other pinsrd xmm5, ebx, 1 add edx, eax converted: jo stub movd xmm6, edx pinsrd xmm6, edi, 1 jmp add
  • 39. Floats, Untyped JIT cmp edi, 0xffffff80 jae stub cmp edi, 0xffffff80 jb skip_convert cmp ebx, 0xffffff81 jne stub cmp edi, 0xffffff81 cvtsi2sd xmm5, eax jne other jmp converted cmp ebx, 0xffffff81 skip_convert: movd xmm5, eax jne other pinsrd xmm5, ebx, 1 add edx, eax converted: jo stub movd xmm6, edx pinsrd xmm6, edi, 1 jmp add cmp ebx, 0xffffff80 jae stub cvtsi2sd xmm6, ecx movd xmm5, eax pinsrd xmm5, ebx, 1 jmp add
  • 40. Floats, Untyped JIT cmp edi, 0xffffff80 jae stub cmp edi, 0xffffff80 jb skip_convert cmp ebx, 0xffffff81 jne stub cmp edi, 0xffffff81 cvtsi2sd xmm5, eax jne other jmp converted cmp ebx, 0xffffff81 skip_convert: movd xmm5, eax jne other pinsrd xmm5, ebx, 1 add edx, eax converted: jo stub movd xmm6, edx pinsrd xmm6, edi, 1 jmp add cmp ebx, 0xffffff80 jae stub cvtsi2sd xmm6, ecx movd xmm5, eax add: pinsrd xmm5, ebx, 1 addsd xmm6, xmm5 jmp add movsd [ebp+0x50], xmm6 movl edx, [ebp+0x50] jmp rejoin
  • 41. Floats, Untyped JIT cmp edi, 0xffffff80 jae stub cmp edi, 0xffffff80 jb skip_convert cmp ebx, 0xffffff81 jne stub cmp edi, 0xffffff81 cvtsi2sd xmm5, eax jne other jmp converted cmp ebx, 0xffffff81 skip_convert: movd xmm5, eax jne other pinsrd xmm5, ebx, 1 add edx, eax converted: jo stub movd xmm6, edx pinsrd xmm6, edi, 1 jmp add cmp ebx, 0xffffff80 jae stub cvtsi2sd xmm6, ecx movd xmm5, eax add: pinsrd xmm5, ebx, 1 addsd xmm6, xmm5 jmp add movsd [ebp+0x50], xmm6 movl edx, [ebp+0x50] jmp rejoin 30 instructions!
  • 43. Benchmark... function distance(a, b) { var t; for (var i = 0; i < a; i++) { for (var j = 0; j < b; j++) { t = ((a - i) * (a - i)) + ((b - j) * (b - j)); } } }
  • 44. The Whole Loop cmp    $0xffffff81,%ebx jne    0xf73ef58f (b - j) cmp    $0xffffff81,%edi cmp    $0xffffff81,%edx jne    0xf73ef353 (a - i) jne    0xf73ef5cc cmp    $0xffffff81,%esi cmp    $0xffffff81,%edx sub    %esi,%eax cmp    $0xffffff81,%edx jne    0xf73ef390 jne    0xf73ef4ce jo     0xf73ef5f4 jne    0xf73ef72b cmp    $0xffffff81,%edi sub    %edx,%ecx cmp    $0xffffff81,%ebx cmp    $0xffffff81,%ebx jne    0xf73ef7f5 jo     0xf73ef3b8 * jne    0xf73ef50b imul   %eax,%ecx jo     0xf73ef550 * jne    0xf73ef768 imul   %edi,%eax jo     0xf73ef7b0 + cmp    $0xffffff81,%ebx jne    0xf73ef832 add    %eax,%edx cmp    $0xffffff81,%edi test   %ecx,%ecx cmp    $0xffffff81,%ebx test   %eax,%eax jo     0xf73ef85a jne    0xf73ef40c je     0xf73ef533 jne    0xf73ef65a je     0xf73ef790 (a - i) cmp    $0xffffff81,%esi jne    0xf73ef449 sub    %edx,%eax (b - j) cmp    $0xffffff81,%edx jne    0xf73ef697 sub    %esi,%edi jo     0xf73ef471 jo     0xf73ef6bf
  • 45. The Whole Loop ~230 instructions cmp    $0xffffff81,%ebx jne    0xf73ef58f (b - j) cmp    $0xffffff81,%edi cmp    $0xffffff81,%edx jne    0xf73ef353 (a - i) jne    0xf73ef5cc cmp    $0xffffff81,%esi cmp    $0xffffff81,%edx sub    %esi,%eax cmp    $0xffffff81,%edx jne    0xf73ef390 jne    0xf73ef4ce jo     0xf73ef5f4 jne    0xf73ef72b cmp    $0xffffff81,%edi sub    %edx,%ecx cmp    $0xffffff81,%ebx cmp    $0xffffff81,%ebx jne    0xf73ef7f5 jo     0xf73ef3b8 * jne    0xf73ef50b imul   %eax,%ecx jo     0xf73ef550 * jne    0xf73ef768 imul   %edi,%eax jo     0xf73ef7b0 + cmp    $0xffffff81,%ebx jne    0xf73ef832 add    %eax,%edx cmp    $0xffffff81,%edi test   %ecx,%ecx cmp    $0xffffff81,%ebx test   %eax,%eax jo     0xf73ef85a jne    0xf73ef40c je     0xf73ef533 jne    0xf73ef65a je     0xf73ef790 (a - i) cmp    $0xffffff81,%esi jne    0xf73ef449 sub    %edx,%eax (b - j) cmp    $0xffffff81,%edx jne    0xf73ef697 sub    %esi,%edi jo     0xf73ef471 jo     0xf73ef6bf
  • 46. The Whole Loop ~230 instructions cmp    $0xffffff81,%ebx jne    0xf73ef58f (b - j) cmp    $0xffffff81,%edi cmp    $0xffffff81,%edx jne    0xf73ef353 (a - i) jne    0xf73ef5cc cmp    $0xffffff81,%esi cmp    $0xffffff81,%edx sub    %esi,%eax cmp    $0xffffff81,%edx jne    0xf73ef390 jne    0xf73ef4ce jo     0xf73ef5f4 jne    0xf73ef72b cmp    $0xffffff81,%edi sub    %edx,%ecx cmp    $0xffffff81,%ebx cmp    $0xffffff81,%ebx jne    0xf73ef7f5 jo     0xf73ef3b8 * jne    0xf73ef50b imul   %eax,%ecx jo     0xf73ef550 * jne    0xf73ef768 imul   %edi,%eax jo     0xf73ef7b0 + cmp    $0xffffff81,%ebx jne    0xf73ef832 add    %eax,%edx cmp    $0xffffff81,%edi test   %ecx,%ecx cmp    $0xffffff81,%ebx test   %eax,%eax jo     0xf73ef85a jne    0xf73ef40c je     0xf73ef533 jne    0xf73ef65a je     0xf73ef790 (a - i) cmp    $0xffffff81,%esi jne    0xf73ef449 sub    %edx,%eax (b - j) cmp    $0xffffff81,%edx jne    0xf73ef697 sub    %esi,%edi jo     0xf73ef471 jo     0xf73ef6bf JägerMonkey runs 100mil iterations in 1012ms
  • 47. Can we do better? function distance(a, b) { var t; for (var i = 0; i < a; i++) { for (var j = 0; j < b; j++) { t = ((a - i) * (a - i)) + ((b - j) * (b - j)); } } }
  • 48. Typed Optimizations function distance(a, b) { var t; for (var i = 0; i < a; i++) { for (var j = 0; j < b; j++) { t = ((a - i) * (a - i)) + ((b - j) * (b - j)); } } }
  • 49. Hoisting Move computation outside of the loop function distance(a, b) { var t; for (var i = 0; i < a; i++) { var t0 = ((a - i) * (a - i)); for (var j = 0; j < b; j++) { t = t0 + ((b - j) * (b - j)); } } }
  • 50. Why only Typed JITs? var ham = 0; var obj = { valueOf: function () { return ham++; } } f(obj, obj);
  • 51. Why only Typed JITs? “ham” must be incremented var ham = 0; var obj = { valueOf: function () { return ham++; } } f(obj, obj);
  • 52. Typed Optimization function distance(a, b) { var t; for (var i = 0; i < a; i++) { var t0 = ((a - i) * (a - i)); for (var j = 0; j < b; j++) { t = t0 + ((b - j) * (b - j)); } } }
  • 53. Elimination Redundant (b - j) function distance(a, b) { eliminated var t; for (var i = 0; i < a; i++) { var t0 = ((a - i) * (a - i)); for (var j = 0; j < b; j++) { var temp = (b - j); t = t0 + (temp * temp); } } }
  • 54. Typed JIT - IonMonkey sub    eax, ecx       ; t0 = (b - j) jo     0xf73ed01d imul   eax, eax       ; t1 = (t0 * t0) jo     0xf73ed022 test   eax, eax je     0xf73ed022 add    ebx, eax       ; t2 = (expr) + t1 jo     0xf73ed027
  • 55. Typed JIT - IonMonkey sub    eax, ecx       ; t0 = (b - j) jo     0xf73ed01d imul   eax, eax       ; t1 = (t0 * t0) jo     0xf73ed022 test   eax, eax je     0xf73ed022 add    ebx, eax       ; t2 = (expr) + t1 jo     0xf73ed027 Runs in 250ms, or 3.8X faster!
  • 56. Smarter sub    eax, ecx       ; t0 = (b - j) jo     0xf73ed01d imul   eax, eax       ; t1 = (t0 * t0) jo     0xf73ed022 add    ebx, eax       ; t2 = (expr) + t1 jo     0xf73ed027 Runs in 220ms, or 4.6X faster!
  • 57. Arithmetic in C movl ecx, ebx subl ecx, ebx imul ecx, ecx addl ecx, esi
  • 58. Arithmetic in C movl ecx, ebx •C: 97ms subl ecx, ebx •Untyped JIT within 10X imul ecx, ecx •Typed JIT within ~2X addl ecx, esi
  • 59. Semantic Gap • No way to tell JS, “use integers” • C distinguishes float/ints

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n