

Rasmus Lerdorf's analysis of XHP  - mattwdelong
http://toys.lerdorf.com/archives/54-A-quick-look-at-XHP.html

======
nostrademons
Heh, now I see why they had to invent HipHop. It's an interesting idea - trade
off speed for readability and security, and then write a PHP->C++ compiler to
recover the speed you've lost. I wonder whether it would've been easier to use
a language + templating system that gets security right in the first place,
though.

~~~
ashu
XHP development started very very recently and had absolutely nothing to do
with HipHop.

~~~
robryan
From those benchmarks though it seems it would only be really effective with
HipHop in a high CPU usage environment.

~~~
jasonlotito
As explained in the comments in the article, it is effective even without
HipHop. Rasmus explains that as well in his article.

------
prodigal_erik

      return $this->renderBaseAttrs() . ' />';
    

No wonder it's expensive. If you serialize a tree of objects by concatenating
subtrees into substrings, most values are copied many times depending on the
depth of the tree, and you end up doing O(n log n) work. But as for the
alternative

    
    
      there was basic XSS filtering in place for the naked
      $_POST['name'] variable in the plain PHP version
    

isn't knowing you have to encode some _but not all_ of your output worse than
just encoding all of it? This is the kind of design mistake that leads to
databases accidentally full of HTML entities. Or more likely, half full.

------
wesley
I see no reason those XHP templates couldn't just be cached as regular old
PHP. It's a nice tool to have during development only.

~~~
rbanffy
Call me old-fashioned, but I have been weary of source-code transformations
since I first touched C++

~~~
flogic
Unless you code in raw machine code, everything is a source code
transformation.

~~~
rbanffy
Yes, but going from one HLL to another is much harder than going from a HLL to
machine code.

Not that I regard PHP a particularly HL language

~~~
nostrademons
Only if you care about the readability and maintainability of the target HLL.

Going from one HLL to another if you never plan to look at or change the
generated code is significantly easier than going to machine code. Just look
at all the compilers that target C.

------
paul
He's benchmarking based off of a 10 line PHP program and then extrapolating
that this is why HPHP is needed?

~~~
codexon
It's a joke.

HPHP's 50% speed boost does not make up for a templating engine that 43 times
slower.

~~~
paul
No, it's stupid because a 10 line program isn't the least bit representative.

~~~
codexon
It doesn't matter if it isn't the least bit representative.

Being 43 times slower is going to make a noticeable impact on latency
especially when the templates are likely to be larger than the example shown.

~~~
paul
No, it's completely meaningless unless your programs are only 10 lines long.
You have no idea what part of it is slower.

------
Daishiman
Well you know what they say about putting lipstick on a pig...

