HipHop: High-Performance PHP Ali-Reza Adl-Tabatabai HipHop Team Facebook.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Microsoft Research March 20, 2000 A Programming Language for Developing Interactive Web Services Claus Brabrand BRICS, University of Aarhus, Denmark.
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
Extensibility, Safety and Performance in the SPIN Operating System Presented by Allen Kerr.
Introduction to Advanced Topics Chapter 1 Mooly Sagiv Schrierber
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
CSE 451: Operating Systems Section 1. Why are you here? 9/30/102.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 1.1 of…
Java for High Performance Computing Jordi Garcia Almiñana 14 de Octubre de 1998 de la era post-internet.
Scripting Languages For Virtual Worlds. Outline Necessary Features Classes, Prototypes, and Mixins Static vs. Dynamic Typing Concurrency Versioning Distribution.
Dynamic Tainting for Deployed Java Programs Du Li Advisor: Witawas Srisa-an University of Nebraska-Lincoln 1.
1 Java Grande Introduction  Grande Application: a GA is any application, scientific or industrial, that requires a large number of computing resources(CPUs,
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Eran Yahav Technion Recent Developments in the Real World 1.
CSc 453 Interpreters & Interpretation Saumya Debray The University of Arizona Tucson.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 03.
ITM352 PHP and Dynamic Web Pages: Server Side Processing.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Owl Andrew Olowude Ben Klingher Belai Lencho Kenneth Cheng Martin Li A language for finite automata Team 20 _________ /_ ___ \ \ \ \__/\___/ / \_\/______/
Programming Languages and Paradigms Object-Oriented Programming.
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
1 October 1, October 1, 2015October 1, 2015October 1, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
Adapted from Prof. Necula UCB CS 1641 Overview of COOL ICOM 4029 Lecture 2 ICOM 4029 Fall 2008.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Crossing The Line: Distributed Computing Across Network and Filesystem Boundaries.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Jan Benda Martin Maly Tomas Matousek Ladislav Prosek Pavel Novak Vaclav Novak Tomas Matousek Department of Software Engineering Faculty.
Introduction and Features of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++
The HipHop Compiler from Facebook By Megha Gupta & Nikhil Kapoor.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
In the name of Allah The Proxy Pattern Elham moazzen.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
Comments in PHP In PHP, we use // to make a singleline comment or /* and */ to make a large comment block. Comment is a part of your PHP code that will.
Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers Kostis Sagonas
©John Samuel 2008 Introduction to PHP. ©John Samuel 2008 Objectives At the end of this class the student will be able to; Create and run a simple php.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
Overview of Java CSCI 392 Day One. Running C code vs Java code C Source Code C Compiler Object File (machine code) Library Files Linker Executable File.
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Chapter 1 Introduction to PHP Part 1. Textbook’s Code DOWNLOADS PHP and MySQL for Dynamic Web Sites Complete Set of Scripts.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
Memory Management in Java Mr. Gerb Computer Science 4.
FASTFAST All rights reserved © MEP Make programming fun again.
First Steps in PHP Creating Very Simple PHP Scripts SoftUni Team Technical Trainers Software University
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
PHP using MySQL Database for Web Development (part II)
Applications Active Web Documents Active Web Documents.
Outline Introduction to the Phalanger System
Introduction to PHP Part 1
Parallel Programming in Contemporary Programming Languages (Part 2)
Towards JIT compiler for IO language Dynamic mixin optimization
PHP.
Intro to PHP.
ICOM 4029 Fall 2003 Lecture 2 (Adapted from Prof. Necula UCB CS 164)
Dynamic Binary Translators and Instrumenters
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
IS 135 Business Programming
Optimizations for Dynamic Languages
Presentation transcript:

HipHop: High-Performance PHP Ali-Reza Adl-Tabatabai HipHop Team Facebook

Facebook: Move fast & build things 3

PHP General-purpose scripting language tailored for web development Interactive Weakly typed & dynamic <?php var_dump(6 + 7); var_dump('6' + '7'); var_dump('six' + 'seven'); var_dump((1<<63) + 0); var_dump((1<<63) + (1<<63)); int(13) int(0) int( ) float( E+19) 4

PHP function foo($x) { echo “foo: “. $x. ”\n”; } foo(“hello”); // prints “foo: hello” foo(10); // prints “foo: 10” 5 General-purpose scripting language tailored for web development Interactive Weakly typed & dynamic

PHP if (...) { class B {... } } else { class B {... } } class C extends B {... } 6 General-purpose scripting language tailored for web development Interactive Weakly typed & dynamic

PHP $a = ‘f’; $b = ‘c’; $c = ‘oo’; $func = $a. $ $b; $func(); 7 General-purpose scripting language tailored for web development Interactive Weakly typed & dynamic

PHP class C { public $declProp = 1; } $obj = new C; $obj->dynProp = 2; // This is OK! echo $obj->declProp. “\n”; // prints “1” echo $obj->dynProp. “\n” // prints “2” 8 General-purpose scripting language tailored for web development Interactive Weakly typed & dynamic

PHP 9 General-purpose scripting language tailored for web development Interactive Weakly typed & dynamic if (function_exists(‘foo’)) {... } if (class_exists($c)) {... }

Memory management PHP is reference counted Precise destruction semantics 10 class C { function __destruct() { echo “bye!”; } } $x = new C; $x = 1; // prints “bye!”

Concurrency Single-threaded programming model Multiple requests run in parallel No shared memory, synchronization, or direct communication 11

Performance...  Source: 12

Implications for Facebook 1.Bad performance can limit user features 2.Poor efficiency requires lots of re$ource$ INTERNET webservers storage... 13

What have we done? Apache Facebook (PHP) PHP/Zend Facebook (binary) Facebook (binary) 14

HipHop compilation flow 15 Facebook (PHP) Facebook (PHP) hphpc Facebook (C++) Facebook (C++) PHP Runtime Webserver Gcc Facebook (binary) Facebook (binary)

HipHop compiler (hphpc) 16 PHP AST Optimize, Infer Types Parser C++ C++ Code Generator VariantDoubleInteger Boolea n StringArrayObject

Representing PHP data type data KindOfString& “Lorem ipsum.” KindOfInt13

Type inference: fewer tags! data & “Lorem ipsum.” 13 type

Basic operations $a + $b

Basic operations: type dispatch $a + $b$a + $b switch (a->m_type) { case KindOfInt: switch (b->m_type) { … } case KindOfArray: switch (b->m_type) { … } … } … } $a + $b

Type inference: avoiding dispatch $a + $b given $a :: Int,$b :: Int add %rcx, %rdx

HipHop compiler: performance 22 Disclaimer: estimated based on running Facebook

HipHop compiler: pros & cons Good for production servers Inadequate for development – Solution: the HipHop interpreter (hphpi) Leverages HipHop runtime & webserver Open problem: 23 Can we get the best of both worlds? hphpi ≠ hphpc

HipHop Virtual Machine (hhvm) Ambitious goal: replace both the HipHop Interpreter and Compiler 24 PHP AST Optimize, Infer Types Parser HHBC Bytecode Generator HHVM Interpreter HHVM JIT HHVM JIT

HipHop bytecode (hhbc) In-house design Stack-base VM Closer to PHP than machine code 25 function lookup($cache, $key) { if (isset($cache[$key])) { echo “Hit! “. $cache[$key]; return true; } else { echo “Miss!”; return false; } 96: Loc 0 101: Loc 1 106: IssetM 113: JmpZ : String “Hit! “ 123: Loc 0 128: Loc 1 133: CGetM 140: Concat 141: Print 142: PopC 143: True 144: RetC 145: String “Miss!” 150: Print 151: PopC 152: False 153: RetC

Hhvm JIT Beyond static type inference: dynamic type specialization 1.Observe types 2.Generate specialized code 3.Guards to check types 26 $n = 3 * $n + 1; 224: Loc 0 229: Int 3 238: Loc 0 243: CGetH 244: Mul 245: Int 1 254: Add 255: SetH 256: PopC ;; Typecheck: int($n)? cmpl $4, -4(%rbp) jne __retranslate ;; Type-spec xlation mov $3, %r12d mov -16(%rbp), %r13 mov %r13, %r14 imul %r14, %r12 add $1, %r12 mov %r12, %r13 mov $0x , %r8 mov %r8, -8(%rbp) mov %r13, -16(%rbp)

Translation cache: Reuse & specialization 27 ;; Typecheck: INT($n)? cmpl $4, -4(%rbp) jne __retranslate ;; Type-spec INT ;; translation... Translation Cache T1: Translator... __retranslate:... Translator... __retranslate:... ;; Typecheck: DOUBLE($n)? cmpl $8, -4(%rbp) jne __retranslate ;; Type-spec DOUBLE ;; translation... T2: T2 $n = 1.5;... $n = 3 * $n + 1;

Current state hhpc – Runs – Paper to appear in SPLASH ‘12 hhvm – works – Developers using it – ~27% slower than hphpc Download from github: 28

Perf progress 6/11-7/14

Ongoing & future work Performance – Profile-guided, SSA-based 2 nd gear JIT – Type prediction – Tuning for the HW – Array shapes: turn hash tables into structs Tracing garbage collection – Copy-on-write arrays – Precise destruction semantics Language extensions 30

Summary PHP enables us to move fast Performance suffers because of interpreter Hiphop compiler – Compiles PHP to C++ offline – Significantly improves user experience & data center efficiency HipHop virtual machine – A new language VM tailored to PHP – Brings dynamic JIT compilation & optimization to PHP Both open sourced on github 31

Thanks! Questions?