Jump to content

Community Info: Php Profile Guided Optimization

Recommended Posts




What if you could get a 0% to 14% (about) boost in performance in your large PHP-based website without changing a line of source code?

There is a a technique called Profile-Guided Optimization or PGO that can offer you a performance boost from 0% (on some cases can't get any extra performance but it will not cause any issues) up to 14%.

The basic idea is as follows: When any program is compiled, the compiler uses some heuristics to determine the most likely path your program will take through the code, and optimizes the code using those assumptions.

PGO lets you train the compiler to produce a more optimized result. It does this by first compiling the code with instrumentation, then run the instrumented code which creates a profile. The final step is to recompile the program, using the profile to fine-tune the optimizations.

This compiler optimization technique that provides better performance gains than the well known -o3 optimization flag in gcc. It is however a bit more work than just setting a flag in the compilation.

Google Chrome uses PGO since version 53 and they saw an up to 15% performance increase for Chrome on Windows. Broken down in different parts of Chrome they got a 14.8% faster new tab page load time, 5.9% faster page load and 16.8% faster startup time. All these performance gains not from optimizing their millions of lines of code, but from using a compiler optimization. Pretty impressive and this works for every program.

As we will see there are two ways to use PGO. The first one is instrumentation based and works as follows: First build the program with an instrumentation flag. The resulting program will gather runtime data that will be used in a second build to optimize the parts of the program that are often used. The other way to use PGO uses perf to gather runtime profile data, which makes the process of gathering data a lot simpler (see below at the AutoFDO section).

One important thing to keep in mind is that the runtime data on which the binary will get optimized has to be a somewhat representative of the actual usage to improve performance. If this is not the case it can also harm the performance. This is also the reason why AutoFDO was created, since it can collect the runtime data from your normal end users instead of a special instrumented build.

When there is no easy way to install it for all server environments i am just giving you the info so you can ask it from your administrator or from your control panel to get the specific instructions for you.

There are a ton of tips about performance, security and stability that most server control panels doesn't offer at all or at least doesn't offer out of the box... Details can make the difference !

So if you decide to give it a try please keep in mind that it will take double time to build 🙂

Enjoy !



Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...