"Is it true that Facebook has developed a high-performance PHP virtual machine that is more than 9 times times faster than the official PHP interpreter," says HHVM.

Source: Internet
Author: User
Tags hhvm
https:// GITHUB.COM/FACEBOOK/HHV m
HHVM (aka the HipHop virtual machine) is a open-source virtual machine designed for executing programs written in Hack an D PHP. HHVM uses a just-in-time compilation approach to achieve superior performance while maintaining the flexibility that PHP D Evelopers is accustomed to. To date, HHVM (and its predecessor HPHPC before it) have realized Over a 9x increase in Web request throughputand Over a 5x reduction in memory consumptionFor Facebook compared with the PHP 5.2 engine + APC.
Note: HHVM supports PHP and hack in two languages for interpretation and compilation.
Hack is FB, a more like the C language of the PHP branch, the addition of type support, syntactically roughly from

$i = 1;

Reply content:

PHP5.2 era, such a test results are possible, this is PHP5.3 dependence, the PHP core team to improve performance in front of the reasons.

HHVM Fast because of the JIT, you can dynamically optimize and recompile the execution at run time:

1.

Like what
// 定义两个functionfunction foo() {}function bar() {}// 调用只用到foo(),没用到bar()foo()
Arguing about this is totally pointless-it's like arguing with a rooster and hen who is more able to order unless you have the opportunity to process billions of levels in order to have access to this. If at that time you have gone beyond the yards, there will be no knowing. So
To have the time or focus on the introduction of technology to understand the basis of language itself ~ ~ Type of dynamic binding changed to static binding ah.
The dynamic binding of a type is cool, but it costs a little.
Cost 1: Type checking takes place at run time.
Cost 2: Variable values are variable in space, and different types require different storage space.
Cost 3: Handling dynamic bindings is usually done by the interpreter. The interpreter is much slower than the compiler, needless to say.

So, if you can get rid of the above several costs, speed up and save memory is of course. Since you know int $ = 1; it's int i=1; you think since c is so much faster than PHP, why HHVM? In fact, talk about the root cause of HHVM or PHP optimization
    • The most common optimization for this type of "dynamic language" is to replace it with other languages (Representative C + +) where performance bottlenecks are present, such as Twitter, which puts a lot of business logic into Scala, and rails is only responsible for the presentation on the front page.
    • Another high-level solution is to optimize the implementation of the official language, such as Zend, if you analyze PHP code, you will find its C code to remove empty line comments after the 80+ Mangyo (PHP 5.2.1), and Zend engine part of less than 100,000 lines.
    • More than the first method, the PHP code is converted to C + +, and then compile the cost of code;
    • The above effect is very significant, but the disadvantage is also obvious, is the cost is very big! Wore, then try to make a better implementation of the virtual machine;
From the development trajectory of HHVM, it is very similar to:
HPHPC------> hphp (hiphop, including HPHPC, HPHPI, HPHPD), which began to be used by Facebook in 08-----> HHVM(Wikipedia: HHVM is built on HPHPC, which translates PHP code into high-level bytecode, and the JIT compiler translates these bytecode into machine code at runtime.) )

And HHVM fast reasons, in various news reports have mentioned Bytecode+jit this key technology, in fact, the way to study the JIT has gone a long time.
Like what:
2010 IBM Japan Research Institute based on their JVM code developed P9, performance is the official PHP 2.5 to 9.5 times times, paper evaluation of a just-in-time compiler retrofitted for PHP /c1>;
2008 Someone used LLVM experiment Zend Virtual machine, the result is 21 times times slower--llvm.org page ;
And the JIT itself will be time-consuming, for some very simple program, the implementation process optimization is not complete, probably more slowly than interpreter, For example, the Java and. NET initial version of the JIT in the performance test is easy to be killed, so there is no absolute thing, more or more in the details of the processing (refer to the HHVM release trajectory), the most critical of the above brothers have said that the type of inference has been transferred from the language to the programmer, HHVM compiled generation The code directly uses the native type, avoids the interpreter to the parameter judgment and the box, the unbox question, precisely this point enhances the performance obviously, even achieves and the C language implementation effect is not small.

There are still some problems with HHVM, such as less support for third-party extensions (such as MongoDB, Redis, on the ground or PHP code), memory leaks, and so on, but in the long run, unless PHP is replaced by others, it is a trend. Without the support of the community, PHP7 is the future, HHVM will only be a flash to a company interview asked Hhvm at that time did not understand the direct answer to the question, is not true. (or incidental conclusions drawn in a given environment)

The benchmark of the CMS framework is observed in many markets, and in most cases the performance of the same environment is PHP7 > Hhvm > PhP5. And the performance gap has not experienced more than 100% cases.

It is worth mentioning that, in the case of direct conversion of PHP5 to HHVM, some CMS third-party modules will produce compatibility issues.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.