SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Kürzlich hochgeladen

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Kürzlich hochgeladen (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Empfohlen

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
 

Empfohlen (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

Hinweis der Redaktion

  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