Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Alternative Operating Systems > How to build the fastest firefox on the planet for Linux or OS X!

How to build the fastest firefox on the planet for Linux or OS X!
Thread Tools
Tyre MacAdmin
Mac Elite
Join Date: Feb 2002
Status: Offline
Reply With Quote
Sep 10, 2009, 03:17 PM
 
I would like to share the success we have had making the fastest Firefox for Linux with the Mac community - this how to, although written for Linux, will easily translate to anyone who knows how to compile on OS X since Linux and OS X are very similar. The first thing to do is to go get a free download of the Intel C++ compiler for Linux or OS X which is available free for non-commercial use. Make sure to install the free license first or the compiler will not work. This 2 stage technique for compiling Firefox uses a compiler optimization called PGO or Profile Guided Optimization that first complies a complete Firefox that you use and as you use it FF learns your unique browsing habits and then uses the data it has collected to build a second firefox that is completely optimized uniquely for you and how you surf. Interesting right? Here is the how to:

First we need to download the Firefox 3.5 source - if you are doing this for Linux you can use our source that has a .mozconfig file:

http://www.linuxdna.com/ff35.tar.lzma

Make a test directory in /root and then extract the ff35.tar.lzma to that /root/test directory.

Now we want to take a look at the .mozconfig file - our file is made for the P4 cpu which is designated by the -xSSE2 in the line:

ac_add_options --enable-optimize="-O3 -xSSE2 -prof-gen=globdata -prof-dir=/root/test/mozilla-build -w"

You can change that to your cpu or leave it for SSE2 optimization as long as your cpu has SSE2 extensions. (If you are using the OS X compiler version the flag might be slightly different.)

Here is the entire .mozconfig file:

ac_add_options --enable-application=browser
mk_add_options MOZ_CO_PROJECT=browser
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/../mozilla-build
ac_add_options --prefix=/opt/firefox-3.5
ac_add_options --enable-optimize="-O3 -xSSE2 -prof-gen=globdata -prof-dir=/root/test/mozilla-build -w"
ac_add_options --enable-default-toolkit=cairo-gtk2
ac_add_options --disable-tests
ac_add_options --disable-javaxpcom
ac_add_options --enable-system-lcms
# ac_add_options --enable-system-sqlite
ac_add_options --with-system-jpeg
# ac_add_options --with-system-png
ac_add_options --with-system-zlib
ac_add_options --with-system-bz2
ac_add_options --disable-debug
ac_add_options --enable-cpp-exceptions
ac_add_options --enable-cpp-rtti
ac_add_options --disable-accessibility
ac_add_options --disable-crashreporter
ac_add_options --disable-installer
ac_add_options --disable-mochitest
ac_add_options --disable-official-branding
ac_add_options --enable-safe-browsing
ac_add_options --enable-xinerama
ac_add_options --enable-canvas
ac_add_options --enable-svg
ac_add_options --enable-pango
ac_add_options --disable-strip

Notice that sqlite and png support has been commented out. You may change that if you are using the latest sqlite and libpng packages on your system.. otherwise your compile will fail.

One final thing about .mozconfig it has a period in front of it so it will not be visible in the directory w/o using the ls -la command.

Now that we have configured the .mozconfig file to our liking we can excute the build once we have sourced our Intel compiler - here is how - you will have a directory with the compiler installed in it... on Linux it will be /opt/intel/ you will need to source the entire directory - if you are using ICC version 11.1.038 and a 32 bit cpu it will look like this:

source /opt/intel/Compiler/11.1/038/bin/iccvars.sh ia32

Note the ia32 at the end with a space before it. That denoted a 32bit system... if you are using a 64bit system it will look like this:

source /opt/intel/Compiler/11.1/038/bin/iccvars.sh intel64

Once we have sourced the compiler we can run this command from the /root/test/mozilla-1.9.1 directory:

make CC=icc CXX=icpc -f client.mk build

The build process will start and after a few min it will halt and complain about pixman-mmx.c not being able to compile. To correct this we must now go to the following directory and modifiy the Makefile:

vi /root/test/mozilla-build/gfx/cairo/libpixman/src/Makefile

Find the second USE_MMX=1 comment and delete it along with these comments also:

MMX_CFLAGS=mmmx -Winline
MMX_CFLAGS+=--param inline-unit-growth=10000 --param large-function-growth=10000
ifdef USE_MMX
CSRCS+= pixman_mmx.c
DEFINES += -DUSE_MMX

There will also be a loose endif above that section... delete it also.

Now we restart the compile back at /root/test/mozill-1.9.1:

make CC=icc CXX=icpc -f client.mk build

There will be two more trouble files that will stop the build - here is how to deal with them:

Once the build stops and complains about nsNavHistory.cpp download the following text file:

http://www.linuxdna.com/ffpgo.txt

if you use cat to display the file you will see two parts copy the first part like so:

g++ -o nsNavHistory.o -c -DXPCOM_TRANSLATE_NSGM_ENTRY_POINT=1 -DMOZILLA_INTERNAL_API -D_IMPL_NS_COM -DEXPORT_XPT_API -DEXPORT_XPTC_API -D_IMPL_NS_COM_OBSOLETE -D_IMPL_NS_GFX -D_IMPL_NS_WIDGET -DIMPL_XREAPI -DIMPL_NS_NET -DIMPL_THEBES -DOSTYPE=\"Linux2.6\" -DOSARCH=Linux -I/root/test/mozilla-1.9.1/toolkit/components/places/src/../../build -I/root/test/mozilla-1.9.1/toolkit/components/places/src -I. -I../../../../dist/include/xpcom -I../../../../dist/include/string -I../../../../dist/include/docshell -I../../../../dist/include/dom -I../../../../dist/include/morkreader -I../../../../dist/include/pref -I../../../../dist/include/necko -I../../../../dist/include/imglib2 -I../../../../dist/include/gfx -I../../../../dist/include/intl -I../../../../dist/include/layout -I../../../../dist/include/locale -I../../../../dist/include/uconv -I../../../../dist/include/unicharutil -I../../../../dist/include/autocomplete -I../../../../dist/include/storage -I../../../../dist/include/txmgr -I../../../../dist/include/nkcache -I../../../../dist/include/widget -I../../../../dist/include/chardet -I../../../../dist/include -I/root/test/mozilla-build/dist/include/nss -I/root/test/mozilla-build/dist/include/nspr -I../../../../dist/include/places -I/root/test/mozilla-build/dist/include/nspr -I/root/test/mozilla-build/dist/sdk/include -fPIC -frtti -fhandle-exceptions -Wall -Wpointer-arith -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-invalid-offsetof -Wno-long-long -pedantic -fno-strict-aliasing -fshort-wchar -pthread -pipe -DNDEBUG -DTRIMMED -O3 -DMOZILLA_CLIENT -include ../../../../mozilla-config.h -Wp,-MD,.deps/nsNavHistory.pp /root/test/mozilla-1.9.1/toolkit/components/places/src/nsNavHistory.cpp

Once you have copied that first long sting go to the following directory:

cd /root/test/mozilla-build/toolkit/components/places/src/

Now paste the entire string to the command line and hit enter. After that cd back to the /root/test/mozilla-1.9.1 directory and start the build over again:

make CC=icc CXX=icpc -f client.mk build

The build will stop one last time - do the exact same thing for the first one but use the second command string in ffpgo.txt

Issue the make command one last time:

make CC=icc CXX=icpc -f client.mk build

Now your system will complete the make and all you have to do is issue the install command:

make CC=icc CXX=icpc -f client.mk install

This will install the Firefox 3.5 stage one to the /opt directory - issue this to start Firefox:

/opt/firefox-3.5/bin/firefox

Now your firefox will be up and running! This is the fun part... use firefox as you normally would for a few days to a week's time... while you are using it Firefox will be generating files called "dyn files. You can see them if you go to the following directory:

/root/test/mozilla-build

The dyn files are "evolutionary data" that firefox will create about your surfing habits. Once you finish your surfing over the next few days we will use these dyn files to generate a screaming fast firefox that is optimized for your particular use!

To recompile the final firefox go to the /root/test/mozilla-build directory and delete everything *but* keep all the .dyn files and the pgopti.sp* files. Now we need to edit the mozconfig file to use the dyn file data and rerun the build again - change the following line in .mozconfig:

ac_add_options --enable-optimize="-O3 -xSSE2 -prof-gen=globdata -prof-dir=/root/test/mozilla-build -w"

to this:

ac_add_options --enable-optimize="-O3 -xSSE2 -prof-use -prof-dir=/root/test/mozilla-build -w"

Now build and install firefox the same way we originally did and stand back! You know have the fastest Firefox available!
( Last edited by Tyre MacAdmin; Sep 12, 2009 at 05:51 PM. )
     
mduell
Posting Junkie
Join Date: Oct 2005
Location: Houston, TX
Status: Offline
Reply With Quote
Sep 10, 2009, 07:06 PM
 
What's this save, a few milliseconds on a pageload? How long does it take to recover your time that it took to create it?
     
Cold Warrior
Moderator
Join Date: Jan 2001
Location: Polwaristan
Status: Offline
Reply With Quote
Sep 10, 2009, 07:15 PM
 
For the layman, what exactly does this process do? I see it's 'optimizing' for SSE2 but is there more beyond that?
     
Tyre MacAdmin  (op)
Mac Elite
Join Date: Feb 2002
Status: Offline
Reply With Quote
Sep 10, 2009, 07:52 PM
 
Originally Posted by mduell View Post
What's this save, a few milliseconds on a pageload? How long does it take to recover your time that it took to create it?
It saves whatever you make it save. The stage 1 feedback binary reflects your own personal usage. It makes whatever you do on your browser faster. It takes less than an hour to compile and then a few days to use it. I think it gives you a lot for free. Of course if you're not the type to compile your own binaries it might not be for you. I will post some benchmarks next week on my system I am breaking in now if you would like
( Last edited by Tyre MacAdmin; Sep 10, 2009 at 08:13 PM. )
     
Tyre MacAdmin  (op)
Mac Elite
Join Date: Feb 2002
Status: Offline
Reply With Quote
Sep 10, 2009, 08:06 PM
 
Originally Posted by Cold Warrior View Post
For the layman, what exactly does this process do? I see it's 'optimizing' for SSE2 but is there more beyond that?
Basically it is like a normal compile where the .mozconfig is where you put in your configure options. The -xSSE2 option can be changed to something like -xW which basically means compile for a P4 with SSE2 vectorization. "Vectorization" is important because it breaks high level code down in to assembly that would otherwise be too "chunky" and slow the system to a crawl. In fact extensions like SSE are one of the big reasons its a good idea to code in C or C++... etc. You can spend less time coding and let the compiler do your dirty work. But where this compile differs is in the PGO implementation that actually gives you the ability to specialize a binary that would otherwise be a "cookie cutter" binary blob that would rely entirely on the cflags like sse2 that you would pass to it in the configure stage. PGO is hard to get working right and Firefox has been compiled on Linux with GCC with out this ability for a while... in fact the reason we decided to get Firefox compiled with PGO is because the Windows firefox actually has been PGO compiled and it is faster than the Linux or OS X version because of that... well at least it was faster... now this build is faster!

So this is the PGO parameters we pass in the mozconfig first stage:

-prof-gen=globdata -prof-dir=/root/test/mozilla-build

And then note it changes in the second compile:

-prof-use -prof-dir=/root/test/mozilla-build
( Last edited by Tyre MacAdmin; Sep 12, 2009 at 05:52 PM. )
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 07:50 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,