My *nix world

Fix Firefox PGO on Linux


As of 2015-03-09 Mozilla Firefox is known as being the fastest web browser out there. Firefox is not only fast but it saves also more memory than Chrome although less than Opera. To make things better it is also an open-source project which means you can stick your fingers into its guts and try making it better (if you can!). Here you may find an exhaustive comparison list of web browsers.

Anyway, Firefox implements the Profile-Guided Optimization (PGO) technique that the GCC 4+ compiler supports.

A PGO build consists of two passes: a first pass to build instrumented binaries, then a second pass to re-build optimized binaries using profile information gleaned from running the instrumented binaries. The Mozilla build system will run both passes for you, as well as a profile generation script in between.


In other words, if you compile the Firefox with PGO support it will generate a better binary version than it normally does. You cannot expect exponential performance boost but anyway, if you just want to squeeze the last byte of your Firefox this would be the way (a quick insight here).


you should expect a double compilation time which on my Intel Core2 Duo E8400 @ 3.00GHz CPU means a hour or so.

The problem

Recently I've observed that I cannot compile the Firefox with PGO support anymore. I usually encounter a compilation error that is related to the pgo-profile.

There are some bug reports related to this issues (see here) but they are old and the proposed fix does not work anymore. Anyway I used them as a start point to understand the problem and the solution. It seems that the does not have the compile rule called pgo-profile-run which in exchange should call the Python script which basically implements a tiny Mozilla profiling server on (make sure this port is not used by any other application you might have running!)

The Fix

So how to fix Firefox PGO on Linux? Well, all you have to do is to add the pgo-profile-run rule in the

If you are on Gentoo and you want to use the Portage emerge utility then you have to create a patch file for the /usr/portage/www-client/firefox/firefox-x.y.z.ebuild file (in my case it was firefox-31.5.0.ebuild) and also to mangle the firefox-x.y.z.ebuild file such that it will call the pgo-profile-run compile run instead of creating the profile server itself.

The required steps are:

  1. unpack manually the firefox-x.y.z.ebuild file
ebuild /usr/portage/www-client/firefox/firefox-31.5.0.ebuild clean unpack
  1. copy the /var/tmp/portage/www-client/firefox-x.y.z/work/mozilla/ as
  2. edit the and make sure you add the following line just before the buildsymbols compile rule:

$(PYTHON) $(topsrcdir)/build/pgo/ $(EXTRA_TEST_ARGS)

  1. create a patch file by comparing the original and the new
diff -u > /usr/portage/www-client/firefox/files/Makefile-pgo.patch
  1. adjust the firefox-x.y.z.ebuild such that it will not try to build the profiling server by itself but it will call pgo-profile-run compile rule instead
    1. So just open the firefox-x.y.z.ebuild file and look for that line that says "if use pgo; then"
    2. comment the original line and insert the new one as below:
# Allow for a proper pgo build
    if use pgo; then
             #       echo "mk_add_options PROFILE_GEN_SCRIPT='\$(PYTHON) \$(OBJDIR)/_profile/pgo/'" >> "${S}"/.mozconfig
             echo "mk_add_options PROFILE_GEN_SCRIPT='EXTRA_TEST_ARGS=10 \$(MAKE) -C \$(MOZ_OBJDIR) pgo-profile-run'" >> "${S}"/.mozconfig
  1. make sure you inform Portage about the change you just did before:
ebuild /usr/portage/www-client/firefox/firefox-x.y.z.ebuild digest

Now you are ready to emerge/compile your firefox with pgo support.

On Gentoo make sure you enable the pgo and test USE flags. If you compile manually using the make tool then read this first.


Using a open source OS (like GNU Linux) and open source projects (like Mozilla Firefox) can be a huge advantage over the commercial/closed project because you have the freedom to change the world, to make it better (your world at least).

Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.

The following two tabs change content below.
Fix Firefox PGO on Linux

Eugen Mihailescu

Founder/programmer/one-man-show at Cubique Software
Always looking to learn more about *nix world, about the fundamental concepts of math, physics, electronics. I am also passionate about programming, database and systems administration. 16+ yrs experience in software development, designing enterprise systems, IT support and troubleshooting.
Fix Firefox PGO on Linux

Latest posts by Eugen Mihailescu (see all)

Tagged on: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *