Live data from Hacker News

Refactored PHP engine makes Wordpress 20% faster

news.php.net

121–130 of 147 posts

Re: Refactored PHP engine makes Wordpress 20% faster

#121

Earlier quoted context omitted.

> No, but I can name a lot of things that are way easier and cleaner to do in Python than in PHP. Please do.

I can name two. First, list comprehensions. In PHP, what you might write as this: $image_urls = []; foreach ($images as $image) { $image_urls[] = 'illos/' . $image['url']; } can just be this in Python: image_urls = ['illos/' + x['url'] for x in images] And, closures in Python -- and to be fair, just about any language that isn't PHP -- close over variables in the scope they're defined automatically, without having to…

  image_urls = images.map { |img| "illos/#{img}" }
Even better :)

Re: Refactored PHP engine makes Wordpress 20% faster

#122

Earlier quoted context omitted.

> No, but I can name a lot of things that are way easier and cleaner to do in Python than in PHP. Please do.

I can name two. First, list comprehensions. In PHP, what you might write as this: $image_urls = []; foreach ($images as $image) { $image_urls[] = 'illos/' . $image['url']; } can just be this in Python: image_urls = ['illos/' + x['url'] for x in images] And, closures in Python -- and to be fair, just about any language that isn't PHP -- close over variables in the scope they're defined automatically, without having to…

I'd prefer something like this:

    $image_urls = array_map(compose(papply('concat', 'illos/'), papply('lookup', 'url')),
                            $images);
This builds a function via composition: first lookup 'url' then prepend with 'illos/'. This function is then mapped over the array.

Unfortunately relies on a bunch of functions which PHP doesn't include. Unfortunately PHP's stdlib concentrates on incredibly-single-purpose functions for, eg. string manipulation, while ignoring general programming constructs. Also, most of the really useful parts of the language aren't available as functions, for no real reason. In any case, we can define these things ourself like this:

    // Function composition
    function compose($f, $g) {
      return function() use ($f, $g) {
        return $f(call_user_func_array($g, func_get_args()));
      };
    }

    // String concatenation. Unfortunately we can't write "concat = papply('implode', '')"
    function concat() {
      return implode('', func_get_args());
    }

    // Array subscript. I'd prefer to do this the other way around and write an
    // argument-flipping function, but that's unnecessary for this example
    function lookup($x, $y) {
      return $y[$x];
    }

    // Partial application
    function papply() {
      $args = func_get_args();
      return function() use ($args) {
        return call_user_func_array('call_user_func',
                                    array_merge($args, func_get_args()));
      };
    }
Regarding lexical scope, Python has ridiculous gotchas too http://stackoverflow.com/questions/5218895/python-nested-fun...

PS: I still much prefer Python to PHP, but straw men aren't going to help ;)

Re: Refactored PHP engine makes Wordpress 20% faster

#123
post #118

Earlier quoted context omitted.

I think you need to qualify that a bit - what are "way more goodies" exactly? Can you name something that Python can do that PHP can't?

Real production ready servers ,complex scientific calculations, 2d, 3d games , to name a few things. PHP is not general purpose. Python is. PHP has type hinting and interfaces that makes it "java" like(it's a strength). Python doesnt have interfaces but allows type hinting through decorators. @typecheck def gimmeFloat(a:int, b:list, c:tuple=(1,2,3)) -> float: return 3.14

And who is talking here about a general purpose lenguage in this context, i only care about the web stuff i don't need things that ain't gonna use.

Re: Refactored PHP engine makes Wordpress 20% faster

#124
post #33

> Wordpress 3.6 – 20.0% gain (253 vs 211 req/sec) How do you generate 211 pages per second on Wordpress to begin with? My server does page generation for my own custom-built blog in ~15ms, but takes a whopping three seconds for a single Wordpress page. I know it's somewhat offtopic and it's about the relative results, but what hardware is this?

This is not a WP issue. It's most likely a bad plugin or theme. You can use something like P3 (Plugin Performance Profiler) to see where the issue is. It could also be a misconfigured system. WP requests should never take 3 sec.

Re: Refactored PHP engine makes Wordpress 20% faster

#125
post #61
post #15

Earlier quoted context omitted.

Just try to imagine HHVM in year or two. Zend PHP will be irrelevant by then.

I'm not sure why you guys ganged up to downvote on something obvious - PHP is loosing grounds to HHVM already. I'm considering it for all my PHP projects already - it's easy to install and most PHP frameworks are well-supported already ( http://hhvm.com/frameworks/ ). I can imagine HHVM having integration within Nginx a la HttpLuaModule, which uses LuaJIT and would eliminate going the FastCGI route.

When HHVM & Hack can easily replace the 10 years of legacy php/html/js soup code and bastardized ZF1 implementations without downtime or extensive developer resources I'll believe it. Unfortunately most non-technical companies only care about performance when it's obviously costing them money (i.e., the servers are crashing.)

Re: Refactored PHP engine makes Wordpress 20% faster

#126
post #123
post #118

Earlier quoted context omitted.

Real production ready servers ,complex scientific calculations, 2d, 3d games , to name a few things. PHP is not general purpose. Python is. PHP has type hinting and interfaces that makes it "java" like(it's a strength). Python doesnt have interfaces but allows type hinting through decorators. @typecheck def gimmeFloat(a:int, b:list, c:tuple=(1,2,3)) -> float: return 3.14

And who is talking here about a general purpose lenguage in this context, i only care about the web stuff i don't need things that ain't gonna use.

It's also a far more readable language, which matters more than anything in large-scale projects

On the other hand, .

Re: Refactored PHP engine makes Wordpress 20% faster

#127

Earlier quoted context omitted.

I can name two. First, list comprehensions. In PHP, what you might write as this: $image_urls = []; foreach ($images as $image) { $image_urls[] = 'illos/' . $image['url']; } can just be this in Python: image_urls = ['illos/' + x['url'] for x in images] And, closures in Python -- and to be fair, just about any language that isn't PHP -- close over variables in the scope they're defined automatically, without having to…

I'd prefer something like this: $image_urls = array_map(compose(papply('concat', 'illos/'), papply('lookup', 'url')), $images); This builds a function via composition: first lookup 'url' then prepend with 'illos/'. This function is then mapped over the array. Unfortunately relies on a bunch of functions which PHP doesn't include. Unfortunately PHP's stdlib concentrates on incredibly-single-purpose functions for, eg.…

[deleted]

Re: Refactored PHP engine makes Wordpress 20% faster

#128
post #101

Earlier quoted context omitted.

His good sense is obvious by the way he stopped going down the JIT route and zeroed in on the bigger performance drain, memory allocation, instead. The smart programmer knows how to write a JIT; the wise programmer knows how to not write a JIT.

JIT is probably coming too, just with current way the engine built it turns out it is very hard to do JIT that makes any real-life impact. One can get magnificent benchmarks, but once you hit real-life apps, you get very low improvement. Thus a more attainable goal was chosen, but JIT may come back yet.

It's been folklore in the Drupal community for years that it's the deeply-nested arrays that are slow. It's Amdahl's law.

Profile Drupal, WordPress and the other heaviest users and look for the big wins.

Re: Refactored PHP engine makes Wordpress 20% faster

#129

Earlier quoted context omitted.

There are many good PHP web frameworks out there today, yes. These don't somehow erase PHP's core flaws as a language though. You can make a new project in Symfony or Laravel, sure, but you'll get that same niceness plus way more goodies if you use a popular Python or Ruby framework.

I think you need to qualify that a bit - what are "way more goodies" exactly? Can you name something that Python can do that PHP can't?

The single biggest everyday-use thing I miss with PHP is keyword arguments. With PHP the only real equivalent is passing an array of arguments and then checking if each possible key exists, and that's just way clunkier.

Re: Refactored PHP engine makes Wordpress 20% faster

#130
post #108

Earlier quoted context omitted.

I can name two. First, list comprehensions. In PHP, what you might write as this: $image_urls = []; foreach ($images as $image) { $image_urls[] = 'illos/' . $image['url']; } can just be this in Python: image_urls = ['illos/' + x['url'] for x in images] And, closures in Python -- and to be fair, just about any language that isn't PHP -- close over variables in the scope they're defined automatically, without having to…

> can just be this in Python: In PHP 5.3+ you can write: $image_urls = array_map(function($image) {return 'illos/'. $image['url'];}, $images); Not as concise, but I'd postulate easier to read for people not familiar with list comprehensions. In PHP 5.5+ there may be another way, but we're stuck with 5.3 in production for most clients, so I'm not up to speed. > And, closures in Python -- and to be fair, just about any…

You can't write production Python and be unfamiliar with list comprehensions. They're a fundamental part of the language.
Post reply on HN