
Facebook releases HHVM, 60 percent faster than its current PHP interpreter - adeelarshad82
https://www.facebook.com/note.php?note_id=10150415177928920&hn=2
======
feralchimp
Hats off.

I have no love for Facebook's product or business model, but their engineering
is diesel, and it's very cool that they're sharing such a deep piece of work.

~~~
pyman
I know some great Facebook engineers and some terrible ones. An ex-colleague
of mine who loves writing spaghetti php code joined Facebook almost a year
ago.

I would say that 30% of Facebook's engineers are top notch, and 70% are just
average php and javascript developers.

~~~
itmag
_I would say that 30% of Facebook's engineers are top notch, and 70% are just
average php and javascript developers._

Pet peeve of mine: why is the word "engineer" thrown around so much on HN? Is
it meant to distinguish a certain class of people from mere coders? Or is it
just a fancy word of saying "coder"?

I've always referred to myself as a coder. Should I change this?

I am genuinely curious, not trying to put anyone down.

~~~
pwaring
It's how Facebook refer to their 'coders', and in many ways it's a better word
because it suggests something more than just hacking [insert language] all
day. For example, an engineer might be concerned about how their code fits
into the bigger picture, whether there is a better way of doing things etc.,
rather than thrashing out code for a daily rate.

------
nupark2
I find it interesting that the economics of inertia work out in favor of
Facebook expending so much effort in improving the performance of a
historically technologically poor language like PHP.

Jason Evans is the author of jemalloc (and more). Given all the things he
would be capable of applying himself to, it's surprising to see him working on
PHP runtime performance (though, the problems are interesting).

~~~
streptomycin
> the performance of a historically technologically poor language like PHP

One of the biggest reasons PHP supplanted Perl as the de facto web programming
language ~10 years ago was that Perl running through CGI was incredibly slower
than PHP.

~~~
themonk
mod_perl was there, it performed better but little bit extra memory footprint.

I don't know why mod_perl was known to very few and PHP become popular.

~~~
rubashov
Shared hosting services offered php. You can't do shared hosting with
mod_perl.

~~~
fallous
Umm, actually you can... it just requires some skills on the apache config
side.

------
yahelc

        var_dump($hit);
    

Good to see that Facebook's engineers still have a startup-y sense of humor.

~~~
sjs
By which you mean juvenile. I don't mean that in a condescending way. No one
wants to work with a bunch of uptight folks. I think it's good too, but let's
call a spade a spade.

~~~
jasone
Believe it or not, my $hit meter was too insensitive to notice the visual
similarity to a four letter word until it was repeatedly pointed out by
readers. Now that we're all on the same wavelength, let's call a spade a
shovel, or even a $hovel, and, well, now we have $hovel and $hit to work with.
Imagine the possibilities.

------
RobAtticus
Interesting that so far most of the comments are pretty positive. Every time
Facebook gives a HipHop talk at my university, it seems the general feeling in
the room is "ugh, why?" The PL people wonder why they're bothering with such a
broken language, and other language zealots get angry that they aren't using
[insert-favorite-language-here].

I wonder if there is a point where they can't squeeze anything more out of
HipHop and have to do a drastic rewrite.

~~~
hvs
The thing is, when they can't squeeze any more out of HipHop, the _last_ thing
they are likely to do is use one of those [insert-favorite-language-here],
because HipHop will be so much faster than any implementation of those other
languages. An important point to remember is that languages, as interesting as
they are, are simply means to translate ideas into machine code. If they
translate it into really fast machine code, it doesn't really matter that much
(except academically) how "correct" the language is. I do not enjoy writing in
PHP, but I have a lot of respect for the real world work that Facebook is
doing with it.

~~~
jrockway
If you want fast, why would you use PHP and then write a new VM, when you
could just use Java or Common Lisp or Haskell or C? Those already exist and
are already damn fast.

~~~
maratd
You could also write your software in assembly and it'll be faster than all of
those you mentioned. The point is to select a language that is feasible for a
business. Facebook is not an academic exercise. PHP has a lower barrier to
entry, which in practical terms reduces the wages that need to be paid. You
then get a few guys who are great at C (PHP is written in C) and fix whatever
parts are getting in the way of great performance. Which is exactly what
Facebook is doing. Remember, Facebook is a business.

~~~
jrockway
Maybe if it's a video decoder that uses special video decoding instructions.
For real world code, though, a good JIT is going to make most code very fast,
and you will actually be able to maintain it. I don't think Java is any harder
to maintain than PHP, but it runs much faster. (I think Perl and Python are
much easier to maintain, however, so if that was what we were arguing about,
then it would make sense. PHP is objectively the worst "P" language.)

~~~
maratd
You're missing my point so completely that it becomes a fine example of why
engineers make poor businessmen.

The best _business_ solution is the one that accomplishes the task at hand
with the least resources. By that metric, PHP is far superior to Java,
regardless of the technical merits at hand.

It costs less to hire an army of PHP devs and a small team to optimize PHP,
than it does to hire an army of Java developers.

<http://www.payscale.com/research/US/Job=PHP_Developer/Salary>

and

[http://www.payscale.com/research/US/Job=Java_Developer/Salar...](http://www.payscale.com/research/US/Job=Java_Developer/Salary)

The difference in pay is around $20K. If you have 500 developers, that's a
difference of $10 mil per year. Over the span of a decade, you're talking
about over $100 million in savings.

As I said, Facebook is a business, not a pet project or an academic exercise.
Decisions on which platform to use and keep are made based on dollars and
cents ... not on which is more elegant or technically superior.

~~~
dhugiaskmak
> It costs less to hire an army of PHP devs and a small team to optimize PHP,
> than it does to hire an army of Java developers.

Is that what Facebook is doing? Everything I've read about interviewing and
getting hired at Facebook leads me to believe that they are not hiring an army
of cheap PHP developers.

------
j_col
Their logging server Scribe, which they also open sourced, is equally awesome.
Kudos to Facebook for releasing such cool technology.

------
oconnor0
The discussion of this over on Ars Technica centered around their current PHP
interpreter being twice as slow as the Zend PHP engine so a 60% improvement
would still leave HHVM slower.

What am I missing?

------
afsina
[http://shootout.alioth.debian.org/u32q/benchmark.php?test=al...](http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=php&lang2=java)

so x30 more to go..

~~~
EricBurnett
Ignoring the fact that these are all running on the standard PHP interpreter,
not one of Facebook's creation...

The benchmarks linked ran on a 4 core machine with varying amounts of
parallelism, generally with Java being more parallelized. When running a
server farm, as Facebook does, aggregate CPU time is more important than wall
time^, since one can easily scale the number of processes to fit the machine.
By CPU time the difference is down a factor of two at least, possibly more.

Be careful with benchmarks. They distill a comparison into a single value for
easy use, but it's not going to be the most appropriate metric in all cases.

^So long as wall time is "sufficiently small", which it generally is.

~~~
SomeOtherGuy
So check the single core version:
[http://shootout.alioth.debian.org/u32/benchmark.php?test=all...](http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=php&lang2=java)

Oh look, PHP is still 30 times slower than java. A 60% improvement to that
still won't get it within an order of magnitude. And PHP is not significantly
faster or easier to develop in than java, so you are losing execution speed to
gain nothing.

~~~
maratd
Java is a compiled language. PHP is not. If you need to do a benchmark to
realize that a compiled language is faster than its dynamic counterpart, then
I really don't know what else to say to you.

~~~
SomeOtherGuy
I don't know why you are saying anything to me since you are responding to
something I didn't say and that has nothing to do with the post I made. Is
"dim witted attempts to respond to poorly thought out strawmen" really the
level of discourse here?

~~~
maratd
What? Who are you responding to?

~~~
SomeOtherGuy
You. You may want to consider that if there's two replies to your post, and
both are "your post is entirely irrelevant", then perhaps your post genuinely
is entirely irrelevant. Protip: read the whole thread from the top.

~~~
maratd
Where did I say "dim witted attempts to respond to poorly thought out
strawmen" or "your post is entirely irrelevant"? Either you're confusing me
with someone else or you don't understand the concept of quotes.

~~~
SomeOtherGuy
Again, read the entire thread. I am not confusing you with anyone else, and I
understand the concept of quotes. You are failing to grasp the context of
posts, and assuming everything anyone puts in quotes must be a statement you
made. There are other people who post, why on earth would you think "your post
is entirely irrelevant" is something I claim you said? I very clearly pointed
out that two people replied _to you_ saying that your post is irrelevant.

~~~
maratd
> I very clearly pointed out that two people replied to you saying that your
> post is irrelevant.

So you're just repeating what other people said? To make yourself feel better?
Still a bit confused.

~~~
SomeOtherGuy
>Still a bit confused

Clearly that is not a situation I can remedy for you. I suggested you read the
thread, as that would resolve the confusion for anyone with basic reading
comprehension skills. If that is not sufficient for you, then you'll need to
ask an adult to explain the words you don't understand.

------
donut
I'll probably get dinged for making a sophomoric observation.

Their example code makes use of the variable $hit, performs a var_dump($hit)
and then returns $hit. Am I the only one that noticed this?

------
nixxle
How easy/hard/logical would it be to implement this for a medium-size website
with about 250k monthly visits?

~~~
leftnode
I don't think it's logical. Stock PHP can _easily_ handle a website with 250k
monthly visits. Or, rather, your speedups will most likely come from talking
to the database less, doing less IO, that sort of thing. CPU probably isn't
your bottleneck now.

~~~
nixxle
Fair enough answer. Thanks! I'll report back when we hit 800m. ^^

~~~
leftnode
The ironic thing about Facebook releasing this is they're (and a handful of
other sites) are the only ones that would really benefit from this. I do love
that they release it as open source.

At my last company, we handled about 20 million API requests a day through a
PHP API. Granted, the request and response were smaller than a standard
webpage, but that was using stock PHP (hell it wasn't even custom compiled, it
came straight from the Debian packages).

So, you need to hit a pretty huge amount of traffic before something like this
makes sense. Of course, it's always neat technology to play with.

~~~
carbocation
Surely you used opcode caching?

~~~
rhu86
Presumably he just installed the php-apc package

------
mkramlich
I have two reactions:

1\. it's still PHP

2\. why are they still using PHP in a world where things like Python, Ruby and
Java exist?

