Faster PHP fo shizzle—HipHop for PHP

[This post is in progress. There may be a number of errors. Please comment below with corrections and I’ll update this article.]

Facebook announced the release of HipHop for PHP today.

Haiping Zhao

Haiping Zhao
Facebook, Palo Alto, California

Sony DSC-WX1
1/80sec @ ƒ2.4, ISO400, 4.2mm (24mm)

When I left Plaxo, Haiping was the server architect there. Today, he works at Facebook and announced HipHop for PHP. It’s nice to see the world recognizing his talents.

Since apparently, I was the first person to ever publicly spill the beans on HipHop, I need to do penance by clarifying what HipHop is and what it means for PHP.

For those of you who don’t have time to read the rest, here is what HipHop for PHP is:

  • HipHop is a PHP-to-C++ cross-compiler. What this means is it takes PHP code and translates it into C++ code for further compiling. It is not another language. It is not a just-in-time compiler (JIT).
  • HipHop will be open-sourced by Facebook under the same licensing as the respective PHP codebase it sets to mirror. Facebook hopes that the community will improve HipHop and add extensions to HipHop that mirror PHP functionality. Also, it hopes that future PHP core development will code features that would be more amenable to optimizations that HipHop does.
  • HipHop was the current survivor of a number of projects over the years at Facebook to improve the performance of the site. Facebook, as the second largest trafficked website in the world, is built mostly on PHP. HipHop is currently running side-by-side next to many LAMP PHP servers at Facebook and they are claiming an average of 2x increase in performance on those machines.
  • HipHop accomplishes this by surveying the entire codebase of your PHP-based application with a parser and then building out a C++ project based on it. The C++ project then compiles and runs as its own web server. Because of this, Apache and the PHP Zend engine are completely bypassed.
  • In order for this to work, some features of the PHP language are no longer supported. Also, C-specific PHP extensions will need to be translated to HipHop C++ extensions in order for them to run.
  • The benefit in speed is mostly due HipHop’s static analyzer which parses your PHP code looking for ways to optimize dynamic parts into static maps. Because of this, your performance gain may vary — more structured code is rewarded with larger performance boosts.

What HipHop means

If you use some open-source PHP applications on your hosted website, the answer is nothing. You don’t have the ability to compile HipHop, you don’t have access to server restricted ports, etc.

If you are developing a PHP application that currently can be run on two servers or less (or virtual servers in the cloud) the answer is nothing. You don’t have the scale for this to be worth your time.

If you do not have a separate development and deployment environment, don’t have a developer who knows C/C++, or use any PHP libraries where the source is not available (thankfully the encoded scripting market is small to non-existent in the PHP world), then the answer is nothing. You don’t have the development model that can support HipHop. Also note, HipHop has bugs, and—given the state of APC development as a model—will never have true compatibility with PHP. You’ll need some resources to either recode around those bugs or fix HipHop.

If you are a developer of an open-source PHP application, then the answer is not much. Most PHP applications will be deployed in a shared-hosted environment. They won’t be using HipHop.

If you are a shared hosting company, the answer is not much. This is because the HipHop parser needs access to all the PHP in an application in order for it to create a working project. The exception is if you provide software as a service that you maintain (say a static build of WordPress, or a custom site tool written in PHP). You can have HipHop optimize this and get the performance increase.

If PHP is not the operational bottleneck of your web application (your app spends a lot of time waiting on the database, disk, a 3rd party Web API call, etc.), the answer is not yet. At this time, there’s no point in getting a performance gain in PHP. If you don’t know what I’m talking about, your bottleneck is the database. 😉

If you have an application already scaled across many machines, a significant number of them running PHP in processor-intensive tasks, have separate development/deployment, have your entire PHP source code, have modest C/C++ resources, then the answer is possibly. It wouldn’t hurt for a developer there to try a hand at cross-compiling the PHP into HipHop and seeing if it runs. An operational deployment will return about 50% of those machines to a pool for other uses or future growth—or, put differently HipHop will basically double that processing on the same hardware/power.

If you make a turnkey application based on PHP, the answer is somewhat. These are rare, but now you can shrink-wrap PHP into a binary. This isn’t the intended use of HipHop, so some development might have to be done to get this fully supported. Also this is a true binary, not an op-code compile—it cannot run across platforms.

If you are developing a PHP framework, the answer is some. If your framework can compile and run successfully in HipHop, then it should be a good selling point to enterprises in case their application becomes bottlenecked on performance.

If you have highly-cohesive parts of your architecture that fall into above requirements and those parts are weakly-coupled (via API?) to the rest of the system, then the answer is a lot. Those parts can probably benefit from HipHop, and it should be relatively easy to try it.

If you are making a decision on which web language to build your site in, the answer is a heck of a lot. Arguing against PHP for performance reasons no longer holds water. PHP under HipHop will probably now out-benchmark Perl, Python, Ruby and possibly even Java and C#. In practice, you can get the advantages of having a scripting language without operational costs. Moreover, because the target is C++ which is more easy to integrate as a library, if you have a multi-language support, you can now provide C++, Python, and other languages with access to components that have before only been written in PHP (without resorting to a web API).

If you are making an argument to recode your entire site from PHP to some other language, the answer is you just lost that argument. (I never bought the argument of recoding an entire site from another language to PHP.)

There are language features, for better or for worse, that PHP must support and HipHop must not. Because of it’s unique approach to compiling, HipHop will never replace the Zend Engine. Because it doesn’t supersede PHP user-space syntax, HipHop does not and will never change PHP development (much).

HipHop is a showcase. With it the PHP world can point to Facebook as being the busiest site built in a scripting language in the world.

Continue reading about A deeper explanation of HipHop after the jump

The Olympus E-Pnext

Olympus launched a teaser site for the next E-Pnext:

Coming Soon

When I first saw this yesterday, it said “You can’t hide creativity…” and it’s since been changed to the unimanginative, “YOUR next camera is coming soon…”

For reference, I decided to see if I could glean it for MY last camera which came last month… the E-P2

MY last camera came last month…

MY last camera came last month…
San Francisco, California

Nikon D3, Nikkor Nikkor 85mm f/1.4D
1/5sec @ ƒ4, ISO200, 85mm

I didn’t have a 17mm pancake like in the picture and my “man-hands” are blocking some of the details, but the E-P2 extends out to my palm, while the photo shows the next one extending out to the woman’s knuckles. The length of my hand should be about right so it’s at most about an inch smaller and just as tall.

Continue reading about Guesses about the next Pen from Olympus after the jump

What (entry) dSLR (to buy)? [The entry kit dSLR Part 4]

(Article continued from part 3)

Unlike in the article four years ago, I’ll be covering specific models. I’ll cover them in the reverse order to my original article, because I felt I gave the less popular brands a short shrift last time.

Pentax

The Pentax K-x ($550 from Adorama, B&H, Amazon)

The Pentax K-x is available in 100 color combinations in Japan.

Four years ago, I stated that Pentax makes shooter-centric cameras at a great value. In fact, I mentioned that Pentax was the first entry in this dSLR price category, and this was in line with Pentax’s history: to bring those people on a budget a quality camera.

Continue reading about Pentax, Sony and Olympus entry dSLRs after the jump

Minimal wallet

Since everyone is on a minimalism kick recently, I decided that my Costanza wallet had to go:

Hlaska Nominal Merge Wallet

Hlaska Nominal Merge Wallet
San Francisco, California

Nikon D3, Nikkor 50mm f/1.4G and Nikkor 85mm f/1.4D, Canon 500D
8 exposures, 1/60sec @ ƒ5, ISO200, 50mm and 85mm

This was taken inside a light tent with my SB-800 flash pointed backwards and an LED light array underneath. No real setup, just some overzealous light bouncing around.

When we were in their flagship store on the Filmore, I had flackette pick out my wallet. When I got home I realized she picked out the same one that I bookmarked a year and a half ago. If you don’t live in the Bay Area, you can also purchase their goods online at various design stores.

I didn’t think to take any photos of the place while I was in the store. I should have since they do their cash register is an executive desk with an iMac 19″ embedded below the desk surface running a copy of Windows in order to do the point-of-sale software. It looked like a big old ergonomic mess, and I asked if it was as stylish-yet-unfunctional as it that seemed. Apparently, according to the clerks, my hunch was right. I guess someone saw Tron too many times.

The wallet has a magnetic money clip and could hold about 8 cards if you really try hard—I have four in there and it’s pretty tight. The animal skin is ostensibly from Italy, but it’s stitched in China. Since the stitching is done with a machine, the threads are pretty tight—not as nice as my Hirano camera case, but what is?

People always ask me about the metal thing is the center of my wallet—It’s a Wallet Pen. I highly recommend them, though I replace the ink with a Fisher universal multi-pen refill.

We’ll see how long I last without membership cards, change, and gum wrappers.

What dSLR (not to buy)? [The entry kit dSLR Part 3]

(Article continued from part 2)

I wrote an article about purchasing an entry dSLR four years ago. What it so surprising is how much of it has stood the test of time—only small details and features have changed: Nikon autofocus now has more points than Canon (as well as better coverage and the use of color); Olympus no longer is the only company with Live View (even Pentax does it), nor the only company with dust shake (all the others, starting with Canon, now offer it); Sony is not the only company with sensor-shift image stabilization.

Still, the essence is still true: Canon and Nikon remain among the last three holdouts adamantly against sensor-based image stabilization. Canon settings are still bulletproof; Nikon still is light focused: with the best autoexposure system and the best high ISO performance. Olympus and Panasonic are still cramming the coolest tech into the smallest space, Sony is proving their engineering chops, and Pentax is still putting photographic value first.

Nikon D5000 w/AF-S Nikkor 50mm f/1.4G
South of Market, San Francisco, California

Olympus E-P2, M.ZUIKO Digital ED 14-42mm 1:3.5-5.6
1/6sec @ ƒ5.2, iso 800, 36mm (72mm)

It’s still best to forego the kit and stick a fast-wide-cheap prime on your camera. This Nikkor 50mm f/1.4 lens is not cheap, but Nikkor 35mm f/1.8 DX lens is the 50mm equivalent for Nikon APS-C and costs about the same as a kit lens. I’ll talk about lenses in a later section.

The rounded right side of the camera is actually an extremely well thought out way for resting smaller these smaller cameras in your palm. It’s a tiny detail, I’ve not seen in the other Nikon models, but it’s just one of the reasons why people rave about Nikon small body dSLR ergonomics.

The advice hasn’t changed: When you buy a first dSLR, it is still the best to forgo the kit lens and plaster on a cheap, fast prime. Lenses still get more expensive, and bodies still get cheaper. Every manufacturer makes a camera for your budget with a negligible price difference…

And the problem is all the cameras are still too good.

In fact, the most significant difference from four years ago is only that the “entry level dSLR” has dropped below $700 for an entire kit, (in addition to) the $1000 “body-only” category—redefining the latter as an “enthusiast” category. Not only that, in many cases, manufacturers have issued multiple models in this sub $700 category, all offering at least one full kit below $550. Three of these sell kits for less than a Canon G11 pocket camera!

Continue reading about The mistake not mentioned after the jump

Why dSLRs (and not pocket cameras)? [The entry kit dSLR Part 2]

(Article continued from part 1)

Bigger in photography means, faster, better, stronger (and more expensive).

Many people will say the only advantage of a digital SLR is that it gives you the flexibility of interchangeable lenses.

I think that’s bullshit.

If it was true, then the days of the dSLR are surely numbered—EVIL has arrived. EVIL, for those of you who don’t know, is an acronym so new, it doesn’t have a Wikipedia page yet. EVIL stands for “electronic viewfinder, interchangeable lens” and they are a new class of camera I’ll talk about another time. Suffice it to say, EVIL will not replace SLR photography—in the same manner that APS-C has not yet dethroned 35mm (much to my surprise). Besides, a lesser-performing EVIL camera costs nearly twice as much as the kits in this article.

I believe the biggest advantage can be found in its name: Single-Lens Reflex.

In order to have a single-lens design, in order to house a reflex mirror, the dSLR has to be big—and bigger, in this case, means faster, better, stronger (and more expensive).

Marie the shooter

Marie the shooter
Elite Cafe, Pacific Heights, San Francisco, California

Leica M8, Carl-Zeiss Biogon 2,8/25 ZM T*
1/45sec @ ƒ2.8, ISO160, 25mm (34mm)

This portrait of Marie and her new Nikon D5000 entry dSLR kit was taken by an APS-H camera, which sits between APS-C and “full frame” in size. Even though this is taken with a wide-angle lens (25mm), you can easily see she really pops from the background.

From your art classes, you may have learned that perspective helps a 2D image show the 3D dimensionality. In photography, another tool, in addition to perspective, is focus via depth-of-field. Focus helps draw the eye, through the visual clutter, to the subject. This tool is nearly non-existent in a pocket digital.

By the way, the lens used in this photo is the highest resolution lens in its class ever produced—the parts that are in focus are really quite sharp. Computed depth-of-field is about half a foot (20cm).

Continue reading about Sometimes bigger is better after the jump

All hail the entry kit! [The entry kit dSLR Part 1]

Yesterday, a friend was interested in purchasing a dSLR at Costco and asked me which he should buy: a Nikon or a Canon. I get asked that a lot.

Costco dSLRs
Costco, South of Market, San Francisco, California

Olympus E-P2, Lumix G Vario HD 1:4.0-5.8/14-140 ASPH. Mega O.I.S.
1/60sec @ ƒ4, ISO250, 14mm (28mm)

From left to right: The Nikon D3000, the Nikon D5000, and the Canon 500D (called the Rebel T1i in the U.S.).

The higher pricing is because Costco usually sells supersets in order to be above the manufacturer minimum advertised price but still yield a decent value to the consumer. For instance, the Nikon D5000 kit contains not only the 18-55mm VR lens, but also the 55-200mm VR lens, a camera bag, two Nikon school DVDs, a book, and an SD card.

The Canon 500D is the most expensive of the trio because Canon and Nikon avoid competing head-to-head by interleaving price and features in models. The 500D sits between the Nikon D5000 and the enthusiast Nikon D90. The 1000D (a.k.a. Rebel XS) was introduced to compete between the Nikon D3000 and Nikon D5000 price points and wasn’t for sale the day I took this photo. (Update: Last time I was at Costco, the Canon 1000D, Nikon D5000, and Canon 500D were for sale. During the writing of this series, Canon introduced the 550D)

“Uhh, the Nikon D3000.”

“Well that’s because they stopped selling the other dSLRs there.”

“Yeah, I noticed that. Why was that?”

“Partly because the Canon 1000D is old. Everyone expects it to be updated.”

“It’ll be updated?”

“Most likely if Canon wants to sell any cameras. It’s been a year and a half, which is a long time to have a camera in that category. The D3000 just came out.”

“You know what camera I really like? The Nikon D5000. In fact, I ordered one the other day. It’s arriving this evening.”

Nikon D5000 kit
South of Market, San Francisco, California

Olympus E-P2, M.ZUIKO Digital ED 14-42mm 1:3.5-5.6
1/60sec @ ƒ3.5, iso 12500, 14mm (28mm)

Actually, this was purchased for Marie, not myself.

It sounds strange that someone who owns a Nikon D70IR, Nikon D200, and a Nikon D3 would purchase an entry level Nikon dSLR. Over the next week, I’ll explain why by going over the Why, What, How, Where and When of a good first dSLR purchase.

And don’t worry. While my experience is with Nikon, I won’t give the short shrift to the other brands.

Table of contents

  • Why dSLR?: Why a dSLR produces better images than a pocket digital
  • What dSLR?: Don’t buy a dSLR that is too much dSLR for you
  • What dSLR? (2): The Pentax, Sony, and Olympus dSLRs and about entry dSLRs compact size
  • How DSLR?: The Canon and Nikon dSLRs, a big spreadsheet, return policies, and what I bought
  • Where dSLR?: About first lenses and things to buy with your first dSLR purchase
  • When dSLR?: About books, videos, and classes

(Article continued in part 2)

Reblog this post [with Zemanta]