🤯 60% OFF BLACK FRIDAY SALE 650+ books, courses & coding assessments!

A Note on Google’s So-called Best Practices

    Troels Knak-Nielsen

    Earlier this week, Google launched a campaign to make the web faster. It appears to be a call for improving the quality of web sites in general, but with a focus on performance.

    The project includes an article on “PHP performance tips”, which is bordering on being ridiculous. There are of course lots of blog posts with similar nonsense around the web, but since this is being endorsed by Google, it’s fair to assume that people might take it at face value. That’s unfortunate, as almost none of it is true. The PHP Team responded back with this message, wherein they refute the unfounded nonsense.

    What’s more troubling however, is the whole approach to performance optimisation as a matter of “knowing the secret handshake”. Optimisation is far more complex than that, and spending time on these “optimisation tricks” are rarely worthwhile and might often lead to unmaintainable code, if applied too early. It’s a fine line, because there are of course certain things that you shouldn’t do (such as hit the database within a tight loop, if you can send one query instead), but there are likewise lots of things that are a complete and utter waste of every body’s time. It’s a pity that this article failed to keep those two issues separate.

    Performance optimisation is not magic. The real way to deal with it, is to measure and analyse. It is almost impossible — even for a highly skilled programmer — to anticipate exactly where there might be bottlenecks in a program. Using a profiler gives you real numbers to relate to, rather than wild guesses and superstition.

    For PHP scripts, there is the freely available Xdebug extension, which provides detailed information on both memory usage and execution time on a per-function basis. It’s easy to install and with the simple WebGrind as a front-end, you’ll be up and running in no time.