SlideShare a Scribd company logo
HipHop Compiler for PHP
  Transforming PHP into C++

       HipHop Compiler Team
          Facebook, Inc.
            May 2010



                              Facebook 2010 (confidential)
PHP is easy to read

<?php

function   tally($count) {
  $sum =   0;
 for ($i   = 0; $i< $count; ++$i) {
    $sum   += $i;
  }
  return   $sum;
}

print tally(10) . “n”;

                                      Facebook 2010 (confidential)
PHP syntax is similar to C++/Java

 <?php

 class Tool extends Object {
   public $name;

     public use($target) {}
 }

 $tool = new Tool();
 $tool->name = „hammer‟;
 $tool->use($nail);

                               Facebook 2010 (confidential)
PHP Statements and Expressions

  FunctionStatement,
  ClassStatement,
  InterfaceStatement,   ExpressionList,
  ClassVariable,        AssignmentExpression,
  ClassConstant,        SimpleVariable,
  MethodStatement,      DynamicVariable,
  StatementList,        StaticMemberExpression,
  BlockStatement,       ArrayElementExpression,
  IfBranchStatement,    DynamicFunctionCall,
  IfStatement,          SimpleFunctionCall,
  WhileStatement,       ScalarExpression,
  DoStatement,          ObjectPropertyExpression,
  ForStatement,         ObjectMethodExpression,
  SwitchStatement,      ListAssignment,
  CaseStatement,        NewObjectExpression,
  BreakStatement,       UnaryOpExpression,
  ContinueStatement,    IncludeExpression,
  ReturnStatement,      BinaryOpExpression,
  GlobalStatement,      QOpExpression,
  StaticStatement,      ArrayPairExpression,
  EchoStatement,        ClassConstantExpression,
  UnsetStatement,       ParameterExpression,
  ExpStatement,         ModifierExpression,
  ForEachStatement,     ConstantExpression,
  CatchStatement,       EncapsListExpression,
  TryStatement,
  ThrowStatement,
                                                  Facebook 2010 (confidential)
PHP is weakly typed

<?php

$a   =   12345;
$a   =   “hello”;
$a   =   array(12345, “hello”, array());
$a   =   new Object();

$c = $a + $b; // integer or array
$c = $a . $b; // implicit casting to strings



                                           Facebook 2010 (confidential)
Core PHP library is small


- Most are in functional style
- ~200 to 500 basic functions

<?php

$len = strlen(“hello”);    // C library
$ret = curl_exec($curl);   // open source




                                     Facebook 2010 (confidential)
PHP is easy to debug

<?php

function tally($count) {
  $sum = 0;
  for ($i = 0; $i< $count; ++$i) {
    $sum += $i;
var_dump($sum);
  }
  return $sum;
}


                                     Facebook 2010 (confidential)
PHP is easy to learn


 easy to read
 easy to write
 easy to debug


      Hello, World!
                            Facebook 2010 (confidential)
PHP is slow 

     http://shootout.alioth.debian.org/u64q/benchmark.ph
                      p?test=all&lang=all
50

40

30

20                                                                     CPU

10

0
     C++    Java    C#    Erlang   Python   Perl      PHP


                                                   Facebook 2010 (confidential)
Why is Zend Engine slow?

 Byte-code interpreter

 Dynamic symbol lookups

  functions, variables, constants
  class methods, properties, constants

 Weakly typing
  zval
  array()
                                     Facebook 2010 (confidential)
Transforming PHP into C++

 g++ is a native code compiler

 static binding

   functions, variables, constants
   class methods, properties, constants

 type inference
   integers, strings, arrays, objects, variants
   struct, vector, map, array
                                      Facebook 2010 (confidential)
Static Binding – Function Calls


<?php
$ret = foo($a);

// C++
Variant v_ret;
Variant v_a;

v_ret = f_foo(v_a);



                         Facebook 2010 (confidential)
Dynamic Function Calls

<?php
$func = „foo‟;
$ret = $func($a);

// C++
Variant v_ret;
Variant v_a;
String v_func;

V_func = “foo”;
v_ret = invoke(v_func, CREATE_VECTOR1(v_a));
                                    Facebook 2010 (confidential)
Function Invoke Table



Variant invoke(CStrReffunc, CArrRefparams) {
  int64 hash = hash_string(func);
  switch (hash) {
  case 1234:
    if (func == “foo”) return foo(params[0])
  }
  throw FatalError(“function not found”);
}


                                    Facebook 2010 (confidential)
Re-declared Functions

<?php
if ($condition) {
  function foo($a) { return $a + 1;}
} else {
  function foo($a) { return $a + 2;}
}
$ret = foo($a);

// C++
if (v_condition) {
g->i_foo = i_foo$$0;
} else {
g->i_foo = i_foo$$1;
}
g->i_foo(v_a);

                                       Facebook 2010 (confidential)
Volatile Functions

<?php
if (!function_exists(„foo‟)) {
bar($a);
} else {
foo($a);
}
function foo($a) {}

// C++
if (f_function_exists(“foo”)) {
f_bar(v_a);
} else {
f_foo(v_a);
}
g->declareFunction(“foo”);

                                  Facebook 2010 (confidential)
Static Binding – Variables

<?php
$foo = „hello‟;
function foo($a) {
global $foo;
  $bar = $foo . $a;
  return $bar;
}

// C++
String f_foo(CStrRefv_a) {
  Variant &gv_foo = g->GV(foo);
  String v_bar;
v_bar = concat(toString(gv_foo), v_a);
  return v_bar;
}

                                         Facebook 2010 (confidential)
GlobalVariables Class


class GlobalVariables : public SystemGlobals {
public:
 // Direct Global Variables
Variant gv_foo;


 // Indirect Global Variables for large compilation
enum _gv_enums {
gv_foo,
 }
Variant gv[1];
};


                                             Facebook 2010 (confidential)
Dynamic Variables

<?php
function foo() {
  $b = 10;
  $a = 'b';
echo($$a);
}

void f_foo() {
 class VariableTable: public RVariableTable {
 public:
   int64 &v_b; String &v_a;
   VariableTable(int64 &r_b, String &r_a) : v_b(r_b), v_a(r_a) {}
   virtual Variant getImpl(const char *s) {
     // hash – switch – strcmp
   }
 } variableTable(v_b, v_a);

echo(variableTable.get("b”));
}

                                                           Facebook 2010 (confidential)
Static Binding – Constants



<?php
define(„FOO‟, „hello‟);
echo FOO;

// C++
echo(“hello” /* FOO */);




                           Facebook 2010 (confidential)
Dynamic Constants

<?php
if ($condition) {
define(„FOO‟, „hello‟);
} else {
define(„FOO‟, „world‟);
}
echo FOO;

// C++
if (v_condition) {
g->declareConstant("FOO", g->k_FOO, "hello”);
} else {
g->declareConstant("FOO", g->k_FOO, "world”);
}
echo(toString(g->k_FOO));

                                                Facebook 2010 (confidential)
Static Binding with Classes

 Class methods

 Class properties

 Class constants

 Re-declared classes

 Deriving from re-declared classes

 Volatile classes



                                      Facebook 2010 (confidential)
Summary - Dynamic Symbol Lookup
     Problem is nicely solved 

 Rule of 90-10

 Dynamic binding is a general form of static
  binding
 Generated code is a super-set of static
  binding and dynamic binding



                                    Facebook 2010 (confidential)
Problem 2. Weakly Typing

 Type Inference

 Runtime Type Info (RTTI)-Guided Optimization

 Type Hints

 Strongly Typed Collection Classes




                                      Facebook 2010 (confidential)
Type Coercions


                 Variant



Double      String     Array   Object



Integer



Boolean

                                  Facebook 2010 (confidential)
Type Inference Example



<?php
$a = 10;
$a = „string‟;


Variant v_a;



                       Facebook 2010 (confidential)
Why is strong type faster?

$a = $b + $c;

if (is_integer($b) &&is_integer($c)) {
  $a = (int)$b + (int)$c;
} else if (is_array($b) &&is_array($c)) {
  $a = array_merge((array)$b + (array)$c);
} else {
  …
}

int64 v_a = v_b + v_c;
                                    Facebook 2010 (confidential)
Type Inference Blockers

<?php
function foo() {
  if ($success) return 10; // integer
  return false; // doh‟
}

$arr[$a] = 10; // doh‟

++$a; // $a can be a string actually!

$a = $a + 1; // $a can become a double, ouch!

                                    Facebook 2010 (confidential)
RTTI-Guided Optimization

<?php
function foo($x) {
  ...
}


foo(10);
foo(„test‟);


void foo(Variantx) {
  ...
}

                        Facebook 2010 (confidential)
Type Specialization Method 1


template<typename T>
void foo(Tx) {
  // generate code with generic T (tough!)
}

-Pros: smaller generated code
-Cons: no type propagation




                                    Facebook 2010 (confidential)
Type Specialization Method 2


void   foo(int64 x) {
  //   generate code assuming x is integer
}
void   foo(Variantx) {
  //   generate code assuming x is variant
}

-Pros: type propagation
-Cons: variant case is not optimized


                                       Facebook 2010 (confidential)
Type Specialization Method 3

void foo(int64 x) {
    // generate code assuming x is integer
}
void foo(Variantx) {
    if (is_integer(x)) {
        foo(x.toInt64()); return;
    }
    // generate code assuming x is variant
}


-Pros: optimized for integer case
-Cons: large code size


                                             Facebook 2010 (confidential)
Type Hints

<?php
function foo(int$a) {
string $b;
}

class bar {
  public array $c;
}

bar $d;


                           Facebook 2010 (confidential)
Strongly Typed Collection Classes

 That omnipotent “array” in PHP 

 Swapping out underlying implementation:
   Array escalation
   PHP classes:
     Vector
     Set
     Map: un-ordered
     Then Array: ordered map
                                 Facebook 2010 (confidential)
Compiler Friendly Scripting Language


If all problems described here are
  considered when designing a new
  scripting language, will it run
  faster than Java?



                             Facebook 2010 (confidential)

More Related Content

What's hot

Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts
Pavan Babu .G
 
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
Bart Feenstra
 
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
Chris Ohk
 
Thumbtack Expertise Days # 5 - Javaz
Thumbtack Expertise Days # 5 - JavazThumbtack Expertise Days # 5 - Javaz
Thumbtack Expertise Days # 5 - Javaz
Alexey Remnev
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
Ismar Silveira
 
Why you-dont-need-design-patterns-in-python
Why you-dont-need-design-patterns-in-pythonWhy you-dont-need-design-patterns-in-python
Why you-dont-need-design-patterns-in-python
Sivanagaraju Pachipulusu
 
Php questions and answers
Php questions and answersPhp questions and answers
Php questions and answers
Deepika joshi
 
November 2009 - JSR-299 Context & Dependency Injection
November 2009 - JSR-299 Context & Dependency InjectionNovember 2009 - JSR-299 Context & Dependency Injection
November 2009 - JSR-299 Context & Dependency Injection
JBug Italy
 
Climbing the Abstract Syntax Tree (Forum PHP 2017)
Climbing the Abstract Syntax Tree (Forum PHP 2017)Climbing the Abstract Syntax Tree (Forum PHP 2017)
Climbing the Abstract Syntax Tree (Forum PHP 2017)
James Titcumb
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : Python
Open Gurukul
 
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
Codemotion
 
Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)
James Titcumb
 
AmI 2017 - Python basics
AmI 2017 - Python basicsAmI 2017 - Python basics
AmI 2017 - Python basics
Luigi De Russis
 
Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)
James Titcumb
 
AmI 2015 - Python basics
AmI 2015 - Python basicsAmI 2015 - Python basics
AmI 2015 - Python basics
Luigi De Russis
 
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
James Titcumb
 
The one thing to list everything
The one thing to list everythingThe one thing to list everything
The one thing to list everything
Daniel Lienert
 
Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)
James Titcumb
 

What's hot (19)

Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts
 
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
 
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
 
Thumbtack Expertise Days # 5 - Javaz
Thumbtack Expertise Days # 5 - JavazThumbtack Expertise Days # 5 - Javaz
Thumbtack Expertise Days # 5 - Javaz
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Why you-dont-need-design-patterns-in-python
Why you-dont-need-design-patterns-in-pythonWhy you-dont-need-design-patterns-in-python
Why you-dont-need-design-patterns-in-python
 
lab4_php
lab4_phplab4_php
lab4_php
 
Php questions and answers
Php questions and answersPhp questions and answers
Php questions and answers
 
November 2009 - JSR-299 Context & Dependency Injection
November 2009 - JSR-299 Context & Dependency InjectionNovember 2009 - JSR-299 Context & Dependency Injection
November 2009 - JSR-299 Context & Dependency Injection
 
Climbing the Abstract Syntax Tree (Forum PHP 2017)
Climbing the Abstract Syntax Tree (Forum PHP 2017)Climbing the Abstract Syntax Tree (Forum PHP 2017)
Climbing the Abstract Syntax Tree (Forum PHP 2017)
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : Python
 
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
 
Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)
 
AmI 2017 - Python basics
AmI 2017 - Python basicsAmI 2017 - Python basics
AmI 2017 - Python basics
 
Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)
 
AmI 2015 - Python basics
AmI 2015 - Python basicsAmI 2015 - Python basics
AmI 2015 - Python basics
 
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
 
The one thing to list everything
The one thing to list everythingThe one thing to list everything
The one thing to list everything
 
Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)
 

Viewers also liked

TAKING PHP SERIOUSLY - Keith Adams
TAKING PHP SERIOUSLY - Keith AdamsTAKING PHP SERIOUSLY - Keith Adams
TAKING PHP SERIOUSLY - Keith Adams
Hermes Alves
 
IPC 2013 - High Performance PHP with HipHop
IPC 2013 - High Performance PHP with HipHopIPC 2013 - High Performance PHP with HipHop
IPC 2013 - High Performance PHP with HipHop
Steve Kamerman
 
Hiphop - PHP
Hiphop - PHPHiphop - PHP
Hiphop - PHP
Ratheesh kumar.R
 
Are you ready to be hacked?
Are you ready to be hacked?Are you ready to be hacked?
Are you ready to be hacked?
Daniel Kanchev
 
HHVM and Hack: A quick introduction
HHVM and Hack: A quick introductionHHVM and Hack: A quick introduction
HHVM and Hack: A quick introduction
Kuan Yen Heng
 
Life As A Fraudster: Carding 101
Life As A Fraudster: Carding 101Life As A Fraudster: Carding 101
Life As A Fraudster: Carding 101
Kount
 
Hello world program
Hello world programHello world program
Hello world program
Spy Seat
 
Whats app Sniffer - How To Hack Whatsapp Messages
Whats app Sniffer - How To Hack Whatsapp Messages Whats app Sniffer - How To Hack Whatsapp Messages
Whats app Sniffer - How To Hack Whatsapp Messages
besthacktoolz
 
C language in hindi (cलेग्वेज इन हिंदी )
C language  in hindi (cलेग्वेज इन हिंदी )C language  in hindi (cलेग्वेज इन हिंदी )
C language in hindi (cलेग्वेज इन हिंदी )
Chand Rook
 
Broiler Production by Dr. Farooq Sarwar
Broiler Production by Dr. Farooq SarwarBroiler Production by Dr. Farooq Sarwar
Broiler Production by Dr. Farooq Sarwar
Farooq Chohadry
 
關於履歷表, 我想說的其實是...
關於履歷表, 我想說的其實是...關於履歷表, 我想說的其實是...
關於履歷表, 我想說的其實是...
Keynes Cheng
 
Indian Army
Indian ArmyIndian Army
Indian Army
Sridhar Srinivas
 
Whatsapp PPT Presentation
Whatsapp PPT PresentationWhatsapp PPT Presentation
Whatsapp PPT Presentation
VOCCE ICT
 
How to become a data scientist in 6 months
How to become a data scientist in 6 monthsHow to become a data scientist in 6 months
How to become a data scientist in 6 months
Tetiana Ivanova
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
whatsapp ppt
whatsapp pptwhatsapp ppt
whatsapp ppt
Swati Luthra
 
Want to keep your IT career? Never stop learning
Want to keep your IT career? Never stop learningWant to keep your IT career? Never stop learning
Want to keep your IT career? Never stop learning
The Art of Service Pty Ltd
 
Deep C
Deep CDeep C
Deep C
Olve Maudal
 

Viewers also liked (20)

TAKING PHP SERIOUSLY - Keith Adams
TAKING PHP SERIOUSLY - Keith AdamsTAKING PHP SERIOUSLY - Keith Adams
TAKING PHP SERIOUSLY - Keith Adams
 
IPC 2013 - High Performance PHP with HipHop
IPC 2013 - High Performance PHP with HipHopIPC 2013 - High Performance PHP with HipHop
IPC 2013 - High Performance PHP with HipHop
 
Hacking
HackingHacking
Hacking
 
Hiphop - PHP
Hiphop - PHPHiphop - PHP
Hiphop - PHP
 
Are you ready to be hacked?
Are you ready to be hacked?Are you ready to be hacked?
Are you ready to be hacked?
 
HHVM and Hack: A quick introduction
HHVM and Hack: A quick introductionHHVM and Hack: A quick introduction
HHVM and Hack: A quick introduction
 
Life As A Fraudster: Carding 101
Life As A Fraudster: Carding 101Life As A Fraudster: Carding 101
Life As A Fraudster: Carding 101
 
Hello world program
Hello world programHello world program
Hello world program
 
Whats app Sniffer - How To Hack Whatsapp Messages
Whats app Sniffer - How To Hack Whatsapp Messages Whats app Sniffer - How To Hack Whatsapp Messages
Whats app Sniffer - How To Hack Whatsapp Messages
 
C language in hindi (cलेग्वेज इन हिंदी )
C language  in hindi (cलेग्वेज इन हिंदी )C language  in hindi (cलेग्वेज इन हिंदी )
C language in hindi (cलेग्वेज इन हिंदी )
 
Broiler Production by Dr. Farooq Sarwar
Broiler Production by Dr. Farooq SarwarBroiler Production by Dr. Farooq Sarwar
Broiler Production by Dr. Farooq Sarwar
 
Whatsapp project work
Whatsapp project workWhatsapp project work
Whatsapp project work
 
關於履歷表, 我想說的其實是...
關於履歷表, 我想說的其實是...關於履歷表, 我想說的其實是...
關於履歷表, 我想說的其實是...
 
Indian Army
Indian ArmyIndian Army
Indian Army
 
Whatsapp PPT Presentation
Whatsapp PPT PresentationWhatsapp PPT Presentation
Whatsapp PPT Presentation
 
How to become a data scientist in 6 months
How to become a data scientist in 6 monthsHow to become a data scientist in 6 months
How to become a data scientist in 6 months
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
whatsapp ppt
whatsapp pptwhatsapp ppt
whatsapp ppt
 
Want to keep your IT career? Never stop learning
Want to keep your IT career? Never stop learningWant to keep your IT career? Never stop learning
Want to keep your IT career? Never stop learning
 
Deep C
Deep CDeep C
Deep C
 

Similar to Hiphop php

OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersLin Yo-An
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7
ZendVN
 
Php mysql
Php mysqlPhp mysql
Php mysql
Alebachew Zewdu
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
✅ William Pinaud
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
julien pauli
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Saraswathi Murugan
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
Stephan Schmidt
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
James Titcumb
 
T3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmerT3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmer
David Muñoz Díaz
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
GeorgePeterBanyard
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Aheadthinkphp
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest UpdatesIftekhar Eather
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
Rowan Merewood
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Bradley Holt
 
ElePHPant7 - Introduction to PHP7
ElePHPant7 - Introduction to PHP7ElePHPant7 - Introduction to PHP7
ElePHPant7 - Introduction to PHP7
Muhammad Hafiz Hasan
 

Similar to Hiphop php (20)

OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
slidesharenew1
slidesharenew1slidesharenew1
slidesharenew1
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
OOP
OOPOOP
OOP
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
 
T3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmerT3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmer
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Ahead
 
The state of DI - DPC12
The state of DI - DPC12The state of DI - DPC12
The state of DI - DPC12
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
ElePHPant7 - Introduction to PHP7
ElePHPant7 - Introduction to PHP7ElePHPant7 - Introduction to PHP7
ElePHPant7 - Introduction to PHP7
 

Recently uploaded

Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 

Recently uploaded (20)

Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 

Hiphop php

  • 1. HipHop Compiler for PHP Transforming PHP into C++ HipHop Compiler Team Facebook, Inc. May 2010 Facebook 2010 (confidential)
  • 2. PHP is easy to read <?php function tally($count) { $sum = 0; for ($i = 0; $i< $count; ++$i) { $sum += $i; } return $sum; } print tally(10) . “n”; Facebook 2010 (confidential)
  • 3. PHP syntax is similar to C++/Java <?php class Tool extends Object { public $name; public use($target) {} } $tool = new Tool(); $tool->name = „hammer‟; $tool->use($nail); Facebook 2010 (confidential)
  • 4. PHP Statements and Expressions FunctionStatement, ClassStatement, InterfaceStatement, ExpressionList, ClassVariable, AssignmentExpression, ClassConstant, SimpleVariable, MethodStatement, DynamicVariable, StatementList, StaticMemberExpression, BlockStatement, ArrayElementExpression, IfBranchStatement, DynamicFunctionCall, IfStatement, SimpleFunctionCall, WhileStatement, ScalarExpression, DoStatement, ObjectPropertyExpression, ForStatement, ObjectMethodExpression, SwitchStatement, ListAssignment, CaseStatement, NewObjectExpression, BreakStatement, UnaryOpExpression, ContinueStatement, IncludeExpression, ReturnStatement, BinaryOpExpression, GlobalStatement, QOpExpression, StaticStatement, ArrayPairExpression, EchoStatement, ClassConstantExpression, UnsetStatement, ParameterExpression, ExpStatement, ModifierExpression, ForEachStatement, ConstantExpression, CatchStatement, EncapsListExpression, TryStatement, ThrowStatement, Facebook 2010 (confidential)
  • 5. PHP is weakly typed <?php $a = 12345; $a = “hello”; $a = array(12345, “hello”, array()); $a = new Object(); $c = $a + $b; // integer or array $c = $a . $b; // implicit casting to strings Facebook 2010 (confidential)
  • 6. Core PHP library is small - Most are in functional style - ~200 to 500 basic functions <?php $len = strlen(“hello”); // C library $ret = curl_exec($curl); // open source Facebook 2010 (confidential)
  • 7. PHP is easy to debug <?php function tally($count) { $sum = 0; for ($i = 0; $i< $count; ++$i) { $sum += $i; var_dump($sum); } return $sum; } Facebook 2010 (confidential)
  • 8. PHP is easy to learn  easy to read  easy to write  easy to debug Hello, World! Facebook 2010 (confidential)
  • 9. PHP is slow  http://shootout.alioth.debian.org/u64q/benchmark.ph p?test=all&lang=all 50 40 30 20 CPU 10 0 C++ Java C# Erlang Python Perl PHP Facebook 2010 (confidential)
  • 10. Why is Zend Engine slow?  Byte-code interpreter  Dynamic symbol lookups  functions, variables, constants  class methods, properties, constants  Weakly typing  zval  array() Facebook 2010 (confidential)
  • 11. Transforming PHP into C++  g++ is a native code compiler  static binding  functions, variables, constants  class methods, properties, constants  type inference  integers, strings, arrays, objects, variants  struct, vector, map, array Facebook 2010 (confidential)
  • 12. Static Binding – Function Calls <?php $ret = foo($a); // C++ Variant v_ret; Variant v_a; v_ret = f_foo(v_a); Facebook 2010 (confidential)
  • 13. Dynamic Function Calls <?php $func = „foo‟; $ret = $func($a); // C++ Variant v_ret; Variant v_a; String v_func; V_func = “foo”; v_ret = invoke(v_func, CREATE_VECTOR1(v_a)); Facebook 2010 (confidential)
  • 14. Function Invoke Table Variant invoke(CStrReffunc, CArrRefparams) { int64 hash = hash_string(func); switch (hash) { case 1234: if (func == “foo”) return foo(params[0]) } throw FatalError(“function not found”); } Facebook 2010 (confidential)
  • 15. Re-declared Functions <?php if ($condition) { function foo($a) { return $a + 1;} } else { function foo($a) { return $a + 2;} } $ret = foo($a); // C++ if (v_condition) { g->i_foo = i_foo$$0; } else { g->i_foo = i_foo$$1; } g->i_foo(v_a); Facebook 2010 (confidential)
  • 16. Volatile Functions <?php if (!function_exists(„foo‟)) { bar($a); } else { foo($a); } function foo($a) {} // C++ if (f_function_exists(“foo”)) { f_bar(v_a); } else { f_foo(v_a); } g->declareFunction(“foo”); Facebook 2010 (confidential)
  • 17. Static Binding – Variables <?php $foo = „hello‟; function foo($a) { global $foo; $bar = $foo . $a; return $bar; } // C++ String f_foo(CStrRefv_a) { Variant &gv_foo = g->GV(foo); String v_bar; v_bar = concat(toString(gv_foo), v_a); return v_bar; } Facebook 2010 (confidential)
  • 18. GlobalVariables Class class GlobalVariables : public SystemGlobals { public: // Direct Global Variables Variant gv_foo; // Indirect Global Variables for large compilation enum _gv_enums { gv_foo, } Variant gv[1]; }; Facebook 2010 (confidential)
  • 19. Dynamic Variables <?php function foo() { $b = 10; $a = 'b'; echo($$a); } void f_foo() { class VariableTable: public RVariableTable { public: int64 &v_b; String &v_a; VariableTable(int64 &r_b, String &r_a) : v_b(r_b), v_a(r_a) {} virtual Variant getImpl(const char *s) { // hash – switch – strcmp } } variableTable(v_b, v_a); echo(variableTable.get("b”)); } Facebook 2010 (confidential)
  • 20. Static Binding – Constants <?php define(„FOO‟, „hello‟); echo FOO; // C++ echo(“hello” /* FOO */); Facebook 2010 (confidential)
  • 21. Dynamic Constants <?php if ($condition) { define(„FOO‟, „hello‟); } else { define(„FOO‟, „world‟); } echo FOO; // C++ if (v_condition) { g->declareConstant("FOO", g->k_FOO, "hello”); } else { g->declareConstant("FOO", g->k_FOO, "world”); } echo(toString(g->k_FOO)); Facebook 2010 (confidential)
  • 22. Static Binding with Classes  Class methods  Class properties  Class constants  Re-declared classes  Deriving from re-declared classes  Volatile classes Facebook 2010 (confidential)
  • 23. Summary - Dynamic Symbol Lookup Problem is nicely solved   Rule of 90-10  Dynamic binding is a general form of static binding  Generated code is a super-set of static binding and dynamic binding Facebook 2010 (confidential)
  • 24. Problem 2. Weakly Typing  Type Inference  Runtime Type Info (RTTI)-Guided Optimization  Type Hints  Strongly Typed Collection Classes Facebook 2010 (confidential)
  • 25. Type Coercions Variant Double String Array Object Integer Boolean Facebook 2010 (confidential)
  • 26. Type Inference Example <?php $a = 10; $a = „string‟; Variant v_a; Facebook 2010 (confidential)
  • 27. Why is strong type faster? $a = $b + $c; if (is_integer($b) &&is_integer($c)) { $a = (int)$b + (int)$c; } else if (is_array($b) &&is_array($c)) { $a = array_merge((array)$b + (array)$c); } else { … } int64 v_a = v_b + v_c; Facebook 2010 (confidential)
  • 28. Type Inference Blockers <?php function foo() { if ($success) return 10; // integer return false; // doh‟ } $arr[$a] = 10; // doh‟ ++$a; // $a can be a string actually! $a = $a + 1; // $a can become a double, ouch! Facebook 2010 (confidential)
  • 29. RTTI-Guided Optimization <?php function foo($x) { ... } foo(10); foo(„test‟); void foo(Variantx) { ... } Facebook 2010 (confidential)
  • 30. Type Specialization Method 1 template<typename T> void foo(Tx) { // generate code with generic T (tough!) } -Pros: smaller generated code -Cons: no type propagation Facebook 2010 (confidential)
  • 31. Type Specialization Method 2 void foo(int64 x) { // generate code assuming x is integer } void foo(Variantx) { // generate code assuming x is variant } -Pros: type propagation -Cons: variant case is not optimized Facebook 2010 (confidential)
  • 32. Type Specialization Method 3 void foo(int64 x) { // generate code assuming x is integer } void foo(Variantx) { if (is_integer(x)) { foo(x.toInt64()); return; } // generate code assuming x is variant } -Pros: optimized for integer case -Cons: large code size Facebook 2010 (confidential)
  • 33. Type Hints <?php function foo(int$a) { string $b; } class bar { public array $c; } bar $d; Facebook 2010 (confidential)
  • 34. Strongly Typed Collection Classes  That omnipotent “array” in PHP   Swapping out underlying implementation:  Array escalation  PHP classes:  Vector  Set  Map: un-ordered  Then Array: ordered map Facebook 2010 (confidential)
  • 35. Compiler Friendly Scripting Language If all problems described here are considered when designing a new scripting language, will it run faster than Java? Facebook 2010 (confidential)