Facebook Releases JIT PHP Compiler 244
angry tapir writes, quoting a Techworld article: "In its continuing endeavor to serve its 800 million users as quickly as possible, Facebook is once again revamping the way it handles its PHP-based Web pages. Facebook has posted ... its HipHop Virtual Machine (HHVM), which the company's engineers call a just-in-time PHP compiler. According to Facebook, this PHP execution engine is 60 percent faster than its current PHP interpreter and uses 90 percent less memory."
Facebook has a weblog post with a more technical description.
First PHP post (Score:5, Funny)
I'd like to launch this discussion by making a snide remark about PHP.
Re: (Score:2)
Yea, perhaps Facebook can now develop a tool for REAL programmers!
Re:First PHP post (Score:5, Funny)
Aren't Facebook programmers already tools?
Is it open sourced? (Score:5, Insightful)
Is FB's JIT PHP open sourced?
Re:Is it open sourced? (Score:5, Informative)
Is FB's JIT PHP open sourced?
It appears to be licensed under a combination of the PHP license and the Zend license. Both are BSD-like, but the Zend license has a clause that requires you to advertise for Zend if you advertise for a product built with the Zend Engine, which I don't much care for.
Re: (Score:3)
Re: (Score:3)
A good thing for the "community" would be if the library was cleaned up. Speeding up a trainwreck only makes the end result that much more catastrophic.
Re: (Score:3)
it makes it easy to write huge spaghetti projects that are expensive to maintain
What language doesn't? Blaming PHP for poorly written code is like blaming a car for having a bad driver.
Re:Is it open sourced? (Score:5, Interesting)
The Zend Engine license [zend.com] seems contradictory to me. On the one hand, Clause 3 says you're forbidden from using the terms "Zend" or "Zend Engine" to endorse or promote your product. On the other hand, Clauses 5 and 6 say you're absolutely required to use the term "Zend Engine" to endorse and promote your product. Seems like someone took the classic BSD license and bolted a commercial land grab onto it, which seems to honor neither the letter nor the spirit of the original.
Re:Is it open sourced? (Score:5, Funny)
I believe it is a license meant for quantic processors... it is required and not required at the same time
Re:Is it open sourced? (Score:4, Insightful)
Re:Is it open sourced? (Score:5, Informative)
If it's not, back to Xcache or APC.
Their "10 times figure" is absolutely correct though, in both Xcache and APC, the compiled binaries to take up 10 times as much space on disk and/or in memory, but to put things in perspective, that's caching memory. It was already consuming that 10 times size when being run directly from php before.
Memory pigs like wordpress eat like 64MB of memory before you even get to plugins. Memory deduplication is required if you are running multiple blogs because the cache files generated by things like SuperCache and MaxCDN also eat up the opcode cache space.
Fun times.
#1 rule of php memory management: NEVER inline html. Many people use it as a easy way to do SSI, but this eats memory, opcode cache or not.
Re: (Score:2)
or eaccelerator.
I had stability issues with both xcache and APC on my production servers where things would go unexpectedly missing from the cache and throw nasty errors.
No such issues with eaccelerator. very happy with that.
Re: (Score:2)
I had the opposite experience. When testing on some newer quad core servers (several years ago), I found that eaccelerator would cause segfaults in Apache that I couldn't pin down to anything in particular. It wasn't hardware either, because it happened on several machines equally. I ditched eaccelerator for APC and things have been peachy since.
Re:Is it open sourced? (Score:5, Informative)
Its on github and depends on open-source libraries.
from the github page:
HipHop is licensed under the PHP and Zend licenses except as otherwise noted.
Its opens source but not copyleft/gpl and if you want to contribute to the project i think you have to sign over the copyright (need facebook login to see the agreement).
Re: (Score:2)
A 4 digit ID and you can't make it to RTFA? :)
Re: (Score:3)
Re: (Score:2)
Re:Is it open sourced? (Score:5, Funny)
Re:Is it open sourced? (Score:5, Funny)
Pffft. Newbie.
Re:First PHP post (Score:5, Funny)
It's too bad PHP doesn't scale.
Re: (Score:2)
Haha. :D
Re: (Score:3)
PHP is the opposite of a simple language. It was simple in the 3.X versions, but nowadays it has too much crap accrued. If you want a simple language, try Lua.
Re: (Score:3)
Re: (Score:3)
Re: (Score:3)
What's ironic is that if Facebooks development team spent half the amount of time they spend trying to make PHP perform well enough for them, writing code in a more conformant language.. they'd be done already.
Re: (Score:2)
VB now, maybe. It might be going a bit far to say PHP is worse than the pre .NET VB that was used to write all those applications in the late 80's-90's though.
Yo Dawgs! (Score:4, Funny)
Da Hip Hop PHP compila is in Da House! Respect bitches!
Re: (Score:3, Funny)
Yo dawg I heard you like PHP, so we put an optimizing JIT compiler in your PHP runtime, so you can execute PHP code while you execute PHP code!
Re: (Score:3, Funny)
Yo dawg I heard you like PHP, so we put an optimizing JIT compiler in your PHP runtime, so you can execute PHP code while you execute PHP code!
Yo mama executes unoptimized PHP!
Re:Yo Dawgs! (Score:5, Funny)
Yo mama's so fat, she thinks strstr(needle, haystack) and strstr(haystack, needle) both sound delicious, she just can't ever remember which one is the one to use.
Yo mama's so fat, she hides food in $a[1] and $a["1"].
Yo mama's so fat, she silently coerces strings into sandwich, and when the interpreter complains, she puts an @ sign in front of it.
Re:Yo Dawgs! (Score:5, Funny)
Yo dawg I heard you like interpreting PHP code, so we put an eval() function in PHP so you can interpret PHP while you interpret PHP!
much more traditional solution (Score:3)
Interesting that they've settled on this approach, which in some ways is much more traditional: developing a high-performance JIT for a dynamic language instead of trying to statically compile a subset. Basically the approach taken by StrongTalk, V8, PyPy, Rubinius, etc.
Re: (Score:3)
Statically compiling a subset would yield much better results, but would be significantly harder to do.
They took the easy way out; this is not a compiler any more than the reference implementation is. It's just a replacement for the reference implementation that sucks a bit less in terms of performance.
So True. (Score:2)
The first 90% of the hhvm project is done; now we're on to the second 90% as we make it really shine.
Re: (Score:2)
From the article....
The first 90% of the hhvm project is done; now we're on to the second 90% as we make it really shine.
Good at math they are not...
Re:So True. (Score:5, Insightful)
http://en.wikipedia.org/wiki/Ninety-ninety_rule [wikipedia.org]
Re: (Score:3)
I generally extend to the third ninety - the last 1% of the code take the third ninety percent of the time. This is a pretty good model for the difference between a good, working program and one with a shiny user interface and most of the beta-bugs worked out.
Or, as someone I worked with who had been at BBN working on the original ARPAnet said, "Take whatever schedule the engineers give you, double it and convert to the next higher units." (two weeks => four months, etc.)
Re:So True. (Score:5, Funny)
Re: (Score:2)
Re: (Score:2)
And when they are finally done optimizing it, squeezing every last bit of performance out of it, adding the ability to compile to a native binary, they will have achieved the remarkable accomplishment of having re-invented the C compiler.
They did that already. They're moving away from static compilation in favor of running it in a VM with a JIT.
Re: (Score:2)
Re: (Score:2)
Which is a complete step backwards if their goal is performance.
Not really. JIT technology is pretty advanced these days. (It's good enough for Java, anyway.) More importantly, though, my understanding is that static compilation forced them to heavily restrict their coding style. PHP being a dynamic language, there were a lot of features they had to leave on the table to make it work that way.
Re: (Score:2, Interesting)
Re:So True. (Score:5, Interesting)
Which is at least 50% slower on its best day, than C/C++ on it's worst day.
Got any numbers to back that up, or are you just pulling it out of thin air?
It's the VM part that kills performance. The Java VM, and presumably, the PHP VM, do not execute native machine instructions, but instead, use an intermediary format, as opposed to, native cpu instructions.
You don't seem to understand how a JIT works. Many portions of Java programs are indeed executed as native machine instructions.
Combine that with the remarkable similarity between PHP syntax and C ( but without the speed )
I wouldn't call the similarity "remarkable." "Superficial" might be a word I'd use, in the sense that Java syntax is also similar to C.
Re: (Score:3)
He asked for numbers.
And I got numbers for you, from PyPy (Python JIT), showing that PyPy is faster then C in some cases.
http://morepypy.blogspot.com/2011/08/pypy-is-faster-than-c-again-string.html [blogspot.com]
Re: (Score:2)
I hate all languages that start with P (Score:3, Funny)
They're just not maintainable in my experience.
Re: (Score:2)
So:
Pascal, Pawn, Perl, PHP, PL/I, Plus, Prolog, PureBasic, and Python ?
Re: (Score:2)
Crap, looks like I missed a few. [wikipedia.org]
Re: (Score:3)
It's ironic how close P and R happen to be. Ruby fan, I take it?
If not Ruby, what do you use for a scripting language? Please don't tell me you decided long ago that if it's possible to do everything in assembly, it must be done in assembly.
Hmm... (Score:2)
Real PHP Compiler (Score:3)
You can find a real PHP compiler at http://phpcompiler.org/ [phpcompiler.org]. It would be nice if the official PHP engine had built in support for loading and running bytecode ( like JVMs ) instead of strictly text code.
Re: (Score:2)
Or Phalanger at http://www.php-compiler.net/ [php-compiler.net] which is a GPL project that compiles to CIL bytecode, which is then run through .NET or Mono in a JIT fashion. It's a proper .NET language, so you get access to the .NET framework as well as the core PHP functions and default extensions. Unfortunately, some of the non-default extensions that they've ported (like gd2 or memcached) are not available in the GPL version.
Re: (Score:3)
Its not really JIT is it? (Score:2)
How is that a JIT VM in any sense of the word?
Re: (Score:3)
I think the Readme on GitHub is a placeholder. They took the Readme from HipHop, aka hphpc, which was the earlier project. This is HipHop VM, which is something different. Read the "more technical description," linked at the top, to get the picture. Basically, HipHop goes PHP-->Abstract Syntax Tree-->C++-->x64. HipHop VM goes PHP-->AST-->Bytecode, then runs the bytecode through a JIT.
dev only (Score:4, Insightful)
Re: (Score:2)
The Hip Hop is wearing off on you my friend.
Re:Mixed feelings (Score:5, Insightful)
That's a step forward for us who rely on crammed share hosting providers, but I strongly believe that PHP has to be phased out in favor of more recent techologies that enforce a clearer (eg DRY, separation of content and logic etc) way of thinking.
Programming languages don't create programming messes. People do.
Re: (Score:3, Insightful)
Re:Mixed feelings (Score:5, Insightful)
Re:Mixed feelings (Score:5, Funny)
You are a disgusting filth and I will loath the existence of people who don't use the right tool for the right job for the rest of my life.
Re:Mixed feelings (Score:5, Insightful)
You are a disgusting filth and I will loath the existence of people who don't use the right tool for the right job for the rest of my life.
You know, people who do fancy stuff with not exactly the right tools were called "hackers".
Re:Mixed feelings (Score:4, Insightful)
You know, people who do fancy stuff with not exactly the right tools were called "hackers".
Only when it's either hard to do so, or when doing that is some kind of a pun. When the only hallmark of such a work is that the result is a bloated mess...no, hacking doesn't have much to do with it.
Re:Mixed feelings (Score:5, Funny)
FTFY.
People who use the wrong tool when the right tool is available are called PHP programmers ;-)
Re:Mixed feelings (Score:5, Interesting)
You know, you hear that kind of weird argument a lot from people who don't realize they've been framework programming on Microsoft platforms. They are always complaining about how primitive PHP is because it doesn't have any "built in" separation between the various heavily abstracted but highly arbitrary layers, and that they don't understand the way PHP abstracts logic, variable classes, magic methods, lambada syntax, etc. They're always pointing to perceived shortcomings in PHP, like the one data interchange layer they know about, or the fact that PHP doesn't pass complete classes as strings. The list goes on for fucking ever. The intentional ignorance of these people annoys the holy shit out of me. Or, well... it used to.
You know, by the same criteria these "evangelist" idiots are using to judge PHP, and failing to apply their idea of "modern", they would be sorely disappointed with any number of other languages. PHP is C++ script. Plane and simple. So if you hate PHP, or you simply can't bring yourself to understand it, it's fair to assume you wouldn't like like C++ either. And for that matter, you certainly wouldn't enjoy Perl, any version of C (other than the sharp kind), Python, Ruby, Java, or any other modern language not developed by our friends in Redmond. None of them would be "modern" enough for you. Or maybe, you're just not skilled enough at your chosen craft. Nobody will ever appreciate the artist who refused to paint because he didn't like the brushes.
PHP isn't the only language that people have written mountains of bad code on either. If you could even begin to understand the mountain of truly nightmarishly bad .net code I've had to wade through over the last decade, you would give me a fucking medal. In fact, I would wager to say that it's easier to write a large, poorly architected application in C# than it is to write one in PHP. Why? Easy. Because Visual Studio doesn't require you to actually think a whole hell of a lot about what you're coding.
When you write something in PHP, it's a direct reflection of your ability to code. That's all it is. Code. Start to finish. You think out a problem, and then you write the code to do it. If you want to seperate it into objects, classes, or layers, you're entitled to. If you have another way to do it, that's also fine.
PHP gives you absolute control and power over whatever it is you want to create. If you're not used to it, or ready for that kind of responsability, it can be frightening.
So I totally understand why lesser programmers hate it.
Personally, I like having options.
Re:Mixed feelings (Score:5, Insightful)
Certain, I'm going to get modded to oblivion for this, but....
Brother I hear your music! PHP is highly underrated! It's a language flexible enough to allow you to just stick a date stamp in the middle of a random webpage, and also write a highly complex, object-oriented application framework with gorgeous abstractions.
Performance is decent, sources are open and don't require compiling, and it's compatible with every webhost and platform out there. It scales well with it's "share nothing" approach, and is one of the most stable software packages I've ever seen. Oh, and the Documentation is excellent.
Sure, it has it's warts: dynamic typing means that in the right contexts, 1==0, and a few others, but these are edge cases in every situation that matters. Most of the problems with OOP in PHP4 have been fixed with the now-almost-universal PHP5.
I can do c, c++, Python, Perl, Javascript, Java, etc. but PHP is my favorite as the Chrysler K-car that doesn't win any looks contests, but always starts and gets you where you want to go, even if only at the legal speed limit.
Re: (Score:3)
dynamic typing means that in the right contexts, 1==0
That's not a fault of dynamic typing. The problem with PHP is that it's weakly typed. You can have dynamic but strong typing, e.g. Smalltalk, Python, Ruby, etc.
Re:Mixed feelings (Score:4, Interesting)
C#'s greatest downfall is those developers/architects that will over-engineer what can be a simple system. PHP's greatest downfall is the sheer popularity in un-trained, or ill-thinking programmers that give the same level of bad taste VB did in the 90's for a lot of people. Bad code can indeed be written in any language, but when a language's core functionality is so poorly conceived, it's harder to write good code. For the record, not very fond of C/C++, but do like Perl okay (for text processing).
Re: (Score:2)
Re:Mixed feelings (Score:4, Informative)
The language changes too rapidly
Erm... what? Have you actually looked at the changelog [php.net] in the past few years? It's all bug fixes, there's absolutely nothing interesting going on there! Development in PHP has completely stagnated for years now. PHP 5.2 was released in 2006 (!!!) and still not everybody has caught on. Then 5.3 came out 3 years later, but it's even rarer to encounter that in the wild. The differences are totally marginal and the stuff they're deprecating is mainly bad stuff from PHP3 and PHP4 that you shouldn't have been using in anything for the last couple of years anyway.
There's a lot wrong with PHP and there's a lot of bad stuff in there, but in my opinion the worst thing about PHP is the lack of progress to improve things. So no, I don't agree the language changes too rapidly, I think it's changing not nearly rapid enough.
Re:Mixed feelings (Score:4, Insightful)
And I quote:
What's your problem? Very well documented! (Score:5, Funny)
And I quote:
What is your problem with this exactly? The functions do exactly what their name suggests. They will either make your head implode or explode!
Re:Mixed feelings (Score:5, Interesting)
I disagree that it promotes bad coding practices. I read that as a bit of a tongue-in-cheek comment that actually encourages people to use it the right way, while at the same time drawing attention to the fact that you can swap parameters and you might get unexpected results (i.e., the function working even though it should throw some sort of type error).
Sometimes mistakes are made in libraries and terrible ugly hacks have to be made to work around them so as not to destroy many hours of work. Whether or not PHP has its share doesn't mean the blame for writing terrible code should be laid entirely at its doorstep.
Certainly a few crappy library functions hasn't soured Facebook on PHP; I for one am glad to see their continued investment in it and - more importantly - their continued practice of open sourcing new and innovative ways of dealing with PHP.
Re: (Score:2)
Re: (Score:2)
Programming languages don't create programming messes. People do.
... and PHP is one of their tools of choice.
Re: (Score:3)
Let me fix that for you:
...and PHP is the choice of tools!
Re: (Score:2)
Let me fix that for you:
Thus, PHP is their preferred tool set.
Re: (Score:2)
more recent techologies that enforce a clearer (eg DRY, separation of content and logic etc) way of thinking.
Yes, please give me more programming languages that enforce a way of thinking on me.
Re: (Score:2)
Re: (Score:2)
As long as your logic is the exact same logic as intended by the author of the language.
Yeah, pass. Support, fine; enforce, see ya.
Re: (Score:2)
Re: (Score:2)
Re: (Score:3)
True; people who don't know how to design software and think that you start creating a solution by programming create programming messes. Programming languages encourage design messes, though. PHP is a programming mess waiting to happen because it attracts people who think that step one is to start coding.
Re: (Score:2)
But what do I care what other people do in PHP or whatever other language? I care about what I can do and what my coleagues can do. We are very good and efficient after 11 years using PHP. I had used Microsoft languages before that and I am very happy to have made the switch to PHP.
Re: (Score:2)
Re:Mixed feelings (Score:5, Insightful)
Re: (Score:3)
Mixed mode is the least of PHP troubles as a language. It's things like silently converting strings to numbers when used as keys of associative arrays that really makes it so irksome .
Re:Mixed feelings (Score:5, Insightful)
Ya know, about 30 years ago, that statement could have been written thusly:
C programs are per se incompatible with the structured programming model. It's a bad programming practice and if you use it, you are doomed to repeat yourself.
Your statement is pretty much equivalent to "never end a sentence with a preposition".
Structured programming eventually failed to take over the world because it imposed too much artificial, restrictive structure. Back then I remarked that "structured programming" was merely a way to force all programs to fit on a flat two-dimensional surface with no crossing lines. Admittedly, such programs are easier to analyze, but are a tiny, tiny subset of the set of interesting and useful programs. For example, one can look at the entire internet as one rather large, complex, multithreaded program.
MVC is a good model, but it ain't the be-all and end-all. All models are an attempt to impose an rational order on what is essentially a linguistic medium (with a veneer of logic). The languages that survive are those that allow the maximum flexibility, with enough support for the tools of analysis and good practice to allow programmers to succeed. C, for example, continues to succeed because it does not have such artificial constraints, but can be adapted to the constraints that the programmer (and the organization) considers important at the time. As a counterexample, see Pascal, or Algol. And don't forget Gõdel.
So, use MVC and DRY. But one day you will find a situation where they get in the way of the most elegant solution. Or, more likely, they will get in the way of hacking a new feature into some legacy POS in time to meet the deadline that Marketing already promised to the client! :D
Re: (Score:2)
So, use MVC and DRY. But one day you will find a situation where they get in the way of the most elegant solution. Or, more likely, they will get in the way of hacking a new feature into some legacy POS in time to meet the deadline that Marketing already promised to the client! :D
Wait, you mean marketing didn't tell the customer the feature was already supported in the shipping version?!?
Re: (Score:2)
Re:Mixed feelings (Score:5, Insightful)
Yeah cause PHP is so bad Facebook use it... no programming language is perfect, they all have their quirks. But your comment is baseless, PHP doesn't make bad programmers, it just doesn't break your legs if you are one.
Re:Mixed feelings (Score:5, Informative)
PHP is like BASIC. In the right hands it can certainly produce just as readable and maintainable code as any other language, but the short learning curve to get to first base invites people with little or no discipline, or often enough, without any underpinnings at all, to write absolute garbage. Worse, this code often ends up being the core of some important infrastructure, and then some poor yob (I was one for several months) has the unlucky job of trying to maintain this garbage. And because the php.ini file allows you turn on all the worst aspects of the language, you end up having to do just that just to keep the damned code running while you try to clean it up.
Oh yes, and apart from the issues I have with the language itself, it has just a plain awful library, with inconsistencies throughout that mean I spend as much time perusing the docs as I do actually coding anything.
Between these two factors, I have to say I hate PHP, but still find myself all too often being forced to deal with it.
Re: (Score:3)
PHP is like BASIC. In the right hands it can certainly produce just as readable and maintainable code as any other language, but the short learning curve to get to first base invites people with little or no discipline, or often enough, without any underpinnings at all, to write absolute garbage.
Would you you prefer that said people stumble their way through something more difficult like C, so that they can produce even worse code than they would have in PHP?
Re: (Score:3)
Re: (Score:2)
More importantly, the short trip to first base causes many "programmers" to constantly run to first base, turn around and go home, rinse and repeat without ever really figuring out what the hell they are doing. They just keep churning out the same crap code that they don't fully understand and breaks in all sorts of ways when you do this, and then that.. now it breaks because they didn't understand it. Then they'll move on to the next project (or another company) and repeat the process until...well.. fore
Re: (Score:3)
"Yeah cause PHP is so bad Facebook use it..."
Yes, for historic reasons.
But look at this very fucking article, they've basically just turned it into Java. That is of course, after they wrote something to turn it into C++ previously.
Which proves the point, that for something large scale and scalable to this degree, then something like C++ or Java from the outset is the best tool for the job. PHP as is has clearly failed to meet Facebook's needs, hence why they've spent the whole year bastardising it into some
Re:Mixed feelings (Score:5, Insightful)
Which means it won't be. PHP has taken hold, and good, bad or ugly, we're stuck with it. There's no phasing it in anything like the short or even medium term. LAMP is everywhere, and countless sites are built on it. It's like COBOL, a bad dream that will keep terrifying us even as better languages flicker and die.
Re: (Score:2)
hip hop has been open source for quite a while. At least a year.
Yes. But this is not about the ahead of time compiler and the interpreter that were released back then, but rather about the new hhvm interpreter, which was released recently [facebook.com].