Background
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).
Caveats:
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 Makefile.in does not have the compile rule called pgo-profile-run which in exchange should call the Python profileserver.py script which basically implements a tiny Mozilla profiling server on 127.0.0.1:8888 (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 Makefile.in.
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:
- unpack manually the firefox-x.y.z.ebuild file
ebuild /usr/portage/www-client/firefox/firefox-31.5.0.ebuild clean unpack
- copy the /var/tmp/portage/www-client/firefox-x.y.z/work/mozilla/Makefile.in as Makefile.in.new
- edit the Makefile.in.new and make sure you add the following line just before the buildsymbols compile rule:
pgo-profile-run:
$(PYTHON) $(topsrcdir)/build/pgo/profileserver.py $(EXTRA_TEST_ARGS)
- create a patch file by comparing the original and the new Makefile.in:
diff -u Makefile.in Makefile.in.new > /usr/portage/www-client/firefox/files/Makefile-pgo.patch
- 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
- So just open the firefox-x.y.z.ebuild file and look for that line that says "if use pgo; then"
- 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/profileserver.py'" >> "${S}"/.mozconfig echo "mk_add_options PROFILE_GEN_SCRIPT='EXTRA_TEST_ARGS=10 \$(MAKE) -C \$(MOZ_OBJDIR) pgo-profile-run'" >> "${S}"/.mozconfig fi
- 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.
Conclusion
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.
Eugen Mihailescu
Latest posts by Eugen Mihailescu (see all)
- Dual monitor setup in Xfce - January 9, 2019
- Gentoo AMD Ryzen stabilizator - April 29, 2018
- Symfony Compile Error Failed opening required Proxies - January 22, 2018