SlideShare a Scribd company logo
Hack & HHVM
by
EWERE DIAGBOYA
Table of Contents
- What is Hack ?
- What is HHVM?
- Installing HHVM
- Some Statistics on HHVM
- Features of Hack
- Code Comparison/Similarity
- Who is using HHVM
- Pros and Cons
- Conclusion
- Demo
What is Hack
Hack is a programming language for HHVM. Hack reconciles the
fast development cycle of a dynamically typed language with
the discipline provided by static typing, while many features
commonly found in other modern languages.
Hack was inspired by PHP, C# and Java so it brings the features
of these languages together into itself to form a single language
with syntax very close to PHP (developed by Facebook)
What is HHVM
HipHop Virtual Machine (HHVM) is a process virtual machine
based on just-in-time (JIT) compilation, serving as an execution
engine for PHP and Hack programming languages.
By using the principle of JIT compilation, executed PHP or Hack
code is first transformed into intermediate HipHop bytecode
(HHBC), which is then dynamically translated into the x86-64
machine code, optimized and natively executed (developed by
Facebook)
HHVM In Summary
Rather than directly interpret or compile PHP code directly to
C++, HHVM compiles Hack and PHP into an intermediate
bytecode. This bytecode is then translated into x64 machine
code dynamically at runtime by a just-in-time (JIT) compiler.
This compilation process allows for all sorts of optimizations
that cannot be made in a statically compiled binary, thus
enabling higher performance of your Hack and PHP programs.
NB: It actually takes a while to compile the code on HHVM but once compiled it can then run faster
and has cache for storing unchanged files to enable it run faster
Installing HHVM
HHVM has Linux ready distros to be deployed on Ubuntu
and others. It is quite easy to install. But HHVM does not
work on all its own, it is configured either on Nginx or
Apache Server
Some Statistics
Statistics
According to Facebook, HHVM has realized over a 9x increase in web
request throughput and over a 5x reduction in memory consumption
for Facebook compared with the Zend PHP engine + APC (which is the
current way of hosting a large majority of PHP applications).
Source: OSCON
Source: OSCON
Some Features of Hack
- Gradual Typing (Static and Dynamic Typing) *
- Collections (Vectors, Set, Map, StableMap)
- Generics *
- Async Functions *
- Lambda Expression
Gradual Typing in Hack
Hack has a unique typing system where the user can
choose to use strict typing or decide not to use typing at
all, which makes it similar to its influencer PHP.
But Facebook warns that to get the full power of HHVM
strict typing is recommended
Gradual Typing in Hack
<?php
string $name = “This is PHP”;
PHP Code
<?hh
string $name = “I am learning Hack”;
Hack Code
Sample Code
Data Types supported in Hack include: bool, int, float, num, string
Generics
Generic programming is a style of computer programming
in which algorithms are written in terms of typesto-be-
specified-later that are then instantiated when needed for
specific types provided as parameters.
In simple terms it allows classes and methods to be
parameterized (i.e. a type associated when a class is
instantiated or a method is called
Generics (Sample Code)
<?hh
class Box<T> {
protected T $data;
public function __construct(T $data) {
$this->data = $data;
}
public function getData(): T {
return $this->data;
}
}
Hack Code
Async Functions
Asynchronous programming refers to a programming
design pattern that allows several distinct tasks to
cooperatively transfer control to one another on a given
thread of execution.
The tasks are isolated from one another from the
perspective of dependency minimization and task
interaction. Asynchronous programming is most often used
in the context of input/output (I/O)
Allow multiple functions to run cooperatively
Async Functions (Sample Code)
<?hh
async function getPage($url) :
Awaitable<string> {
sfp = fopen($url, ‘r’);
return await async_get_contents($fp);
}
// Sends all requests in parallel,
// blocks for response
$pages = await (
getPage(‘http://php.net’),
getpage(‘http://example.com’),
getPage(‘http://hhvm.com’),
);
Hack Code
Comparison & Similarity
<?hh
class MyClass {
public function alpha(): int {
return 1;
}
public function beta(): string {
return 'hi test';
}
}
function f(MyClass $my_inst): string {
return $my_inst->beta();
}
Hack Code
<?php
class MyClass {
public function alpha() {
return 1
}
public function beta() {
return ‘hi test’;
}
function f() {
return $this->beta();
}
PHP Code
Who is using HHVM ?
Advantages of Hack & HHVM
- More Features in Hack than PHP
- Runs faster than PHP
- Higher general perform and less resource usage
- Compatible with alot of CMS and Frameworks
(Magento, CodeIgniter, CakePHP, Laravel etc)
- Compiles to a more efficient native code
- Only recompiles when changes are made to a file
Disadvantages of Hack & HHVM
- Compile Time might be high
- Learning a new syntax might take a while
- Incompatibility issues with PHP & HHVM
- Facebook could stop support for Hack & HHVM which
could slow down its growth
- Does not allow direct HTML in its code
Conclusion
PHP is an old language and very dear to alot of us but
Hack and HHVM show us better ways to improve our code
and build features that do not currently exist on PHP, and
give the performance PHP is yet to give.
The final option might be to run good old PHP on HHVM
and still get good performance or learn Hack and use the
new tools it presents. Either way the goal is to increase
performance with less resources and give the user a
better experience of the application
Demo
Simple POST in Hack
Thank you
Further Reading
www.hacklang.org
www.hhvm.com
www.github.com/facebook/hhvm
www.github.com/hhvm

More Related Content

What's hot

Apache Thrift
Apache ThriftApache Thrift
Apache Thrift
knight1128
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Php’s guts
Php’s gutsPhp’s guts
Php’s guts
Elizabeth Smith
 
Introduction to php php++
Introduction to php php++Introduction to php php++
Introduction to php php++
Tanay Kishore Mishra
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to Dart
Ramesh Nair
 
Unit VI
Unit VI Unit VI
RESTLess Design with Apache Thrift: Experiences from Apache Airavata
RESTLess Design with Apache Thrift: Experiences from Apache AiravataRESTLess Design with Apache Thrift: Experiences from Apache Airavata
RESTLess Design with Apache Thrift: Experiences from Apache Airavata
smarru
 
An introduction to Apache Thrift
An introduction to Apache ThriftAn introduction to Apache Thrift
An introduction to Apache Thrift
Mike Frampton
 
Programming in hack
Programming in hackProgramming in hack
Programming in hack
Alejandro Marcu
 
Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016
Rouven Weßling
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
julien pauli
 
Presentation of Python, Django, DockerStack
Presentation of Python, Django, DockerStackPresentation of Python, Django, DockerStack
Presentation of Python, Django, DockerStack
David Sanchez
 
50 shades of PHP
50 shades of PHP50 shades of PHP
50 shades of PHP
Maksym Hopei
 
What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?
Rouven Weßling
 
Go lang introduction
Go lang introductionGo lang introduction
Go lang introduction
yangwm
 
Doing It Wrong with Puppet -
Doing It Wrong with Puppet - Doing It Wrong with Puppet -
Doing It Wrong with Puppet -
Puppet
 
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
Mahmoud Masih Tehrani
 
PHP 5.3
PHP 5.3PHP 5.3
PHP 5.3
Chris Stone
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.
Mosky Liu
 
Peek at PHP 7
Peek at PHP 7Peek at PHP 7
Peek at PHP 7
John Coggeshall
 

What's hot (20)

Apache Thrift
Apache ThriftApache Thrift
Apache Thrift
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Php’s guts
Php’s gutsPhp’s guts
Php’s guts
 
Introduction to php php++
Introduction to php php++Introduction to php php++
Introduction to php php++
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to Dart
 
Unit VI
Unit VI Unit VI
Unit VI
 
RESTLess Design with Apache Thrift: Experiences from Apache Airavata
RESTLess Design with Apache Thrift: Experiences from Apache AiravataRESTLess Design with Apache Thrift: Experiences from Apache Airavata
RESTLess Design with Apache Thrift: Experiences from Apache Airavata
 
An introduction to Apache Thrift
An introduction to Apache ThriftAn introduction to Apache Thrift
An introduction to Apache Thrift
 
Programming in hack
Programming in hackProgramming in hack
Programming in hack
 
Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
Presentation of Python, Django, DockerStack
Presentation of Python, Django, DockerStackPresentation of Python, Django, DockerStack
Presentation of Python, Django, DockerStack
 
50 shades of PHP
50 shades of PHP50 shades of PHP
50 shades of PHP
 
What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?
 
Go lang introduction
Go lang introductionGo lang introduction
Go lang introduction
 
Doing It Wrong with Puppet -
Doing It Wrong with Puppet - Doing It Wrong with Puppet -
Doing It Wrong with Puppet -
 
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
 
PHP 5.3
PHP 5.3PHP 5.3
PHP 5.3
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.
 
Peek at PHP 7
Peek at PHP 7Peek at PHP 7
Peek at PHP 7
 

Similar to Hack and HHVM

Hack language
Hack languageHack language
Hack language
Ravindra Bhadane
 
PHP
PHPPHP
Php&amp;yii2
Php&amp;yii2Php&amp;yii2
Php&amp;yii2
RakhiBhojwani
 
chapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdfchapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdf
burasyacob012
 
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
Jackson F. de A. Mafra
 
An Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP ProgrammersAn Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP Programmers
jphl
 
How PHP works
How PHP works How PHP works
Unit 1
Unit 1Unit 1
Php ppt
Php pptPhp ppt
PHP ITCS 323
PHP ITCS 323PHP ITCS 323
PHP ITCS 323
Sleepy Head
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
sushil kumar
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
Nguyễn Hoà
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
vigneswaran54
 
Php ppt
Php pptPhp ppt
Php ppt
Sasi Kumar
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Sasi Kumar
 
Daniel Sloof: Magento on HHVM
Daniel Sloof: Magento on HHVMDaniel Sloof: Magento on HHVM
Daniel Sloof: Magento on HHVM
Meet Magento Poland
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
Basic php
Basic phpBasic php
Basic php
salissal
 
Basics PHP
Basics PHPBasics PHP
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
SHARANBAJWA
 

Similar to Hack and HHVM (20)

Hack language
Hack languageHack language
Hack language
 
PHP
PHPPHP
PHP
 
Php&amp;yii2
Php&amp;yii2Php&amp;yii2
Php&amp;yii2
 
chapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdfchapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdf
 
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
 
An Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP ProgrammersAn Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP Programmers
 
How PHP works
How PHP works How PHP works
How PHP works
 
Unit 1
Unit 1Unit 1
Unit 1
 
Php ppt
Php pptPhp ppt
Php ppt
 
PHP ITCS 323
PHP ITCS 323PHP ITCS 323
PHP ITCS 323
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php ppt
Php pptPhp ppt
Php ppt
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Daniel Sloof: Magento on HHVM
Daniel Sloof: Magento on HHVMDaniel Sloof: Magento on HHVM
Daniel Sloof: Magento on HHVM
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Basic php
Basic phpBasic php
Basic php
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 

More from Ewere Diagboya

DevOps lagos meetup
DevOps lagos meetupDevOps lagos meetup
DevOps lagos meetup
Ewere Diagboya
 
DevOps Demystified
DevOps DemystifiedDevOps Demystified
DevOps Demystified
Ewere Diagboya
 
AWS Well Architected Framework in Summary
AWS Well Architected Framework in SummaryAWS Well Architected Framework in Summary
AWS Well Architected Framework in Summary
Ewere Diagboya
 
Serverless - Increasing software delivery
Serverless -  Increasing software deliveryServerless -  Increasing software delivery
Serverless - Increasing software delivery
Ewere Diagboya
 
Logs, metrics and real time data analytics
Logs, metrics and real time data analyticsLogs, metrics and real time data analytics
Logs, metrics and real time data analytics
Ewere Diagboya
 
webservers
webserverswebservers
webservers
Ewere Diagboya
 
Digital Marketting
Digital MarkettingDigital Marketting
Digital Marketting
Ewere Diagboya
 
Escrow & Payment Explosion in Africa
Escrow & Payment Explosion in AfricaEscrow & Payment Explosion in Africa
Escrow & Payment Explosion in Africa
Ewere Diagboya
 
E1BX0VRZRB6PZ85
E1BX0VRZRB6PZ85E1BX0VRZRB6PZ85
E1BX0VRZRB6PZ85
Ewere Diagboya
 

More from Ewere Diagboya (9)

DevOps lagos meetup
DevOps lagos meetupDevOps lagos meetup
DevOps lagos meetup
 
DevOps Demystified
DevOps DemystifiedDevOps Demystified
DevOps Demystified
 
AWS Well Architected Framework in Summary
AWS Well Architected Framework in SummaryAWS Well Architected Framework in Summary
AWS Well Architected Framework in Summary
 
Serverless - Increasing software delivery
Serverless -  Increasing software deliveryServerless -  Increasing software delivery
Serverless - Increasing software delivery
 
Logs, metrics and real time data analytics
Logs, metrics and real time data analyticsLogs, metrics and real time data analytics
Logs, metrics and real time data analytics
 
webservers
webserverswebservers
webservers
 
Digital Marketting
Digital MarkettingDigital Marketting
Digital Marketting
 
Escrow & Payment Explosion in Africa
Escrow & Payment Explosion in AfricaEscrow & Payment Explosion in Africa
Escrow & Payment Explosion in Africa
 
E1BX0VRZRB6PZ85
E1BX0VRZRB6PZ85E1BX0VRZRB6PZ85
E1BX0VRZRB6PZ85
 

Hack and HHVM

  • 2. Table of Contents - What is Hack ? - What is HHVM? - Installing HHVM - Some Statistics on HHVM - Features of Hack - Code Comparison/Similarity - Who is using HHVM - Pros and Cons - Conclusion - Demo
  • 3. What is Hack Hack is a programming language for HHVM. Hack reconciles the fast development cycle of a dynamically typed language with the discipline provided by static typing, while many features commonly found in other modern languages. Hack was inspired by PHP, C# and Java so it brings the features of these languages together into itself to form a single language with syntax very close to PHP (developed by Facebook)
  • 4. What is HHVM HipHop Virtual Machine (HHVM) is a process virtual machine based on just-in-time (JIT) compilation, serving as an execution engine for PHP and Hack programming languages. By using the principle of JIT compilation, executed PHP or Hack code is first transformed into intermediate HipHop bytecode (HHBC), which is then dynamically translated into the x86-64 machine code, optimized and natively executed (developed by Facebook)
  • 5. HHVM In Summary Rather than directly interpret or compile PHP code directly to C++, HHVM compiles Hack and PHP into an intermediate bytecode. This bytecode is then translated into x64 machine code dynamically at runtime by a just-in-time (JIT) compiler. This compilation process allows for all sorts of optimizations that cannot be made in a statically compiled binary, thus enabling higher performance of your Hack and PHP programs.
  • 6. NB: It actually takes a while to compile the code on HHVM but once compiled it can then run faster and has cache for storing unchanged files to enable it run faster
  • 7. Installing HHVM HHVM has Linux ready distros to be deployed on Ubuntu and others. It is quite easy to install. But HHVM does not work on all its own, it is configured either on Nginx or Apache Server
  • 9. Statistics According to Facebook, HHVM has realized over a 9x increase in web request throughput and over a 5x reduction in memory consumption for Facebook compared with the Zend PHP engine + APC (which is the current way of hosting a large majority of PHP applications).
  • 12. Some Features of Hack - Gradual Typing (Static and Dynamic Typing) * - Collections (Vectors, Set, Map, StableMap) - Generics * - Async Functions * - Lambda Expression
  • 13. Gradual Typing in Hack Hack has a unique typing system where the user can choose to use strict typing or decide not to use typing at all, which makes it similar to its influencer PHP. But Facebook warns that to get the full power of HHVM strict typing is recommended
  • 14. Gradual Typing in Hack <?php string $name = “This is PHP”; PHP Code <?hh string $name = “I am learning Hack”; Hack Code Sample Code Data Types supported in Hack include: bool, int, float, num, string
  • 15. Generics Generic programming is a style of computer programming in which algorithms are written in terms of typesto-be- specified-later that are then instantiated when needed for specific types provided as parameters. In simple terms it allows classes and methods to be parameterized (i.e. a type associated when a class is instantiated or a method is called
  • 16. Generics (Sample Code) <?hh class Box<T> { protected T $data; public function __construct(T $data) { $this->data = $data; } public function getData(): T { return $this->data; } } Hack Code
  • 17. Async Functions Asynchronous programming refers to a programming design pattern that allows several distinct tasks to cooperatively transfer control to one another on a given thread of execution. The tasks are isolated from one another from the perspective of dependency minimization and task interaction. Asynchronous programming is most often used in the context of input/output (I/O) Allow multiple functions to run cooperatively
  • 18. Async Functions (Sample Code) <?hh async function getPage($url) : Awaitable<string> { sfp = fopen($url, ‘r’); return await async_get_contents($fp); } // Sends all requests in parallel, // blocks for response $pages = await ( getPage(‘http://php.net’), getpage(‘http://example.com’), getPage(‘http://hhvm.com’), ); Hack Code
  • 19. Comparison & Similarity <?hh class MyClass { public function alpha(): int { return 1; } public function beta(): string { return 'hi test'; } } function f(MyClass $my_inst): string { return $my_inst->beta(); } Hack Code <?php class MyClass { public function alpha() { return 1 } public function beta() { return ‘hi test’; } function f() { return $this->beta(); } PHP Code
  • 20. Who is using HHVM ?
  • 21. Advantages of Hack & HHVM - More Features in Hack than PHP - Runs faster than PHP - Higher general perform and less resource usage - Compatible with alot of CMS and Frameworks (Magento, CodeIgniter, CakePHP, Laravel etc) - Compiles to a more efficient native code - Only recompiles when changes are made to a file
  • 22. Disadvantages of Hack & HHVM - Compile Time might be high - Learning a new syntax might take a while - Incompatibility issues with PHP & HHVM - Facebook could stop support for Hack & HHVM which could slow down its growth - Does not allow direct HTML in its code
  • 23. Conclusion PHP is an old language and very dear to alot of us but Hack and HHVM show us better ways to improve our code and build features that do not currently exist on PHP, and give the performance PHP is yet to give. The final option might be to run good old PHP on HHVM and still get good performance or learn Hack and use the new tools it presents. Either way the goal is to increase performance with less resources and give the user a better experience of the application