You are not logged in.

#1 2013-10-01 23:29:30

krnlpk
Member
Registered: 2010-01-03
Posts: 25

Why is extra/firefox compiled with -O2 instead of -O3?

Several years ago Mozilla tackled the chronical slowness of Linux Firefox with -O3 and aggressive optimizations in its builds. Current official x86_64 build of FF 24.0 from mozilla in about:buildconfig reports this GCC options:

-Wall -Wpointer-arith -Wdeclaration-after-statement -Werror=return-type -Wtype-limits -Wempty-body -Wsign-compare -Wno-unused -Wcast-align -std=gnu99 -fgnu89-inline -fno-strict-aliasing -ffunction-sections -fdata-sections -pthread -pipe -DNDEBUG -DTRIMMED -g -fprofile-use -fprofile-correction -Wcoverage-mismatch -O3 -fomit-frame-pointer

Arch ships its own build of Firefox, compiled internally with -O2, which suffers of a noticeable lag in rendering if compared with the official release; so, why doing it if even Mozilla considers O3 compilation of Firefox sufficiently stable for a public release?

Last edited by krnlpk (2013-10-01 23:30:20)

Offline

#2 2013-10-01 23:36:17

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Why is extra/firefox compiled with -O2 instead of -O3?

There was https://bugs.archlinux.org/task/37068 but I guess it suggested too many changes.

Offline

#3 2013-10-02 07:10:55

phw
Member
Registered: 2013-05-27
Posts: 318

Re: Why is extra/firefox compiled with -O2 instead of -O3?

The comment in the PKGBUILD suggests that setting the optimization level is some kind of workaround:

https://projects.archlinux.org/svntogit … irefox#n61

Does not explain why it uses -o2 instead of -o3, though. If this makes a measurable difference you might want to open a bug report for the package.

Offline

#4 2013-10-02 07:23:44

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,365
Website

Re: Why is extra/firefox compiled with -O2 instead of -O3?

phw wrote:

The comment in the PKGBUILD suggests that setting the optimization level is some kind of workaround:

https://projects.archlinux.org/svntogit … irefox#n61

That is nothing to do with this.

Offline

#5 2013-10-02 08:27:54

krnlpk
Member
Registered: 2010-01-03
Posts: 25

Re: Why is extra/firefox compiled with -O2 instead of -O3?

phw wrote:

The comment in the PKGBUILD suggests that setting the optimization level is some kind of workaround:

https://projects.archlinux.org/svntogit … irefox#n61

Does not explain why it uses -o2 instead of -o3, though. If this makes a measurable difference you might want to open a bug report for the package.

Yes, it does. I'm now using official x86_64 build, and it's way faster in rendering. I haven't changed nothing - no rm -rf ~/.mozilla, no extension removed, nothing, I've just untarred the FTP build and created a .desktop to use it - and is absolutely incomparable.

I really can't understand why the PKGBUILD does not reflect the official build CFLAGS/CXXFLAGS, in this 2011 blog post from Mike Hommey, a long time Mozilla employee, you can see how they just started to optimize aggressively firefox with GCC since version 6, and if it's good for mozilla, I can't understand why it should be different for us.

Last edited by krnlpk (2013-10-02 08:28:36)

Offline

#6 2013-10-02 08:47:02

krnlpk
Member
Registered: 2010-01-03
Posts: 25

Re: Why is extra/firefox compiled with -O2 instead of -O3?

ok, wait a second, arch build reports in about:buildconfig

gcc     gcc version 4.8.1 20130725 (prerelease) (GCC)   -D_FORTIFY_SOURCE=2 -Wall -Wpointer-arith -Wdeclaration-after-statement -Werror=return-type -Wtype-limits -Wempty-body -Wsign-compare -Wno-unused -Wcast-align -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -std=gnu99 -fgnu89-inline -fno-strict-aliasing -ffunction-sections -fdata-sections -pthread -pipe -DNDEBUG -DTRIMMED -g -fprofile-use -fprofile-correction -Wcoverage-mismatch -O3 -fomit-frame-pointer
c++     gcc version 4.8.1 20130725 (prerelease) (GCC)   -D_FORTIFY_SOURCE=2 -Wall -Wpointer-arith -Woverloaded-virtual -Werror=return-type -Wtype-limits -Wempty-body -Wsign-compare -Wno-invalid-offsetof -Wcast-align -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -fno-exceptions -fno-strict-aliasing -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions -std=gnu++0x -pthread -pipe -DNDEBUG -DTRIMMED -g -fprofile-use -fprofile-correction -Wcoverage-mismatch -O3 -fomit-frame-pointer -D_FORTIFY_SOURCE

Why are both -O2 and -O3 set? this has no sense.

Edit:
Looking in GCC sources (gcc.c) :
"A -O switch is obsoleted by a later -O switch.", so this code is compiled with -O3 anyway. So, why mozilla build is a bit faster than arch one? I can't explain this.
The only thing that arch adds are a bit of options for hardening like -fstack-protector, -D_FORTIFY_SOURCE=2 and --param=ssp-buffer-size=4, which can have a negative impact on performances, by the way.

Last edited by krnlpk (2013-10-02 09:26:00)

Offline

#7 2013-10-02 11:41:41

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,390

Re: Why is extra/firefox compiled with -O2 instead of -O3?

Does the webpages look the same?
In the past i noticed that too, but the fonts looked way better on arch.


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#8 2013-10-02 13:11:07

krnlpk
Member
Registered: 2010-01-03
Posts: 25

Re: Why is extra/firefox compiled with -O2 instead of -O3?

kokoko3k wrote:

Does the webpages look the same?
In the past i noticed that too, but the fonts looked way better on arch.

They are absolutely the same, IMHO.

Offline

#9 2013-10-02 13:36:59

Awebb
Member
Registered: 2010-05-06
Posts: 6,275

Re: Why is extra/firefox compiled with -O2 instead of -O3?

The package states, that there are two maintainers and one packager, all of them should be within the range of an email. I also recommend asking such a question at the mailing list, as forum people have the tendency to discuss everything only based on logic, which is futile, unless somebody with actual information turns up.

I'd file a new bug. The old one was closed because of the other two things the guy wanted, your request seems valid. You might want to create a benchmark (not just a "it feels faster").

Offline

#10 2013-10-02 19:13:36

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Why is extra/firefox compiled with -O2 instead of -O3?

krnlpk wrote:

The only thing that arch adds are a bit of options for hardening like -fstack-protector, -D_FORTIFY_SOURCE=2 and --param=ssp-buffer-size=4, which can have a negative impact on performances, by the way.

So try building without them, and compare.

Offline

#11 2013-10-03 01:54:31

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,131

Re: Why is extra/firefox compiled with -O2 instead of -O3?

For comparison, this is what I have in about:buildconfig. (I'm using Mozilla's build as Arch's doesn't work for me.)

Build Machine

bld-linux64-ec2-345

Source

Built from http://hg.mozilla.org/releases/mozilla- … 3b0732e765

Build platform

target
x86_64-unknown-linux-gnu

Build tools

Compiler     Version     Compiler flags

/tools/gcc-4.7.3-0moz1/bin/gcc     gcc version 4.7.3 (GCC)     -Wall -Wpointer-arith -Wdeclaration-after-statement -Werror=return-type -Wtype-limits -Wempty-body -Wsign-compare -Wno-unused -Wcast-align -std=gnu99 -fgnu89-inline -fno-strict-aliasing -ffunction-sections -fdata-sections -pthread -pipe -DNDEBUG -DTRIMMED -g -fprofile-use -fprofile-correction -Wcoverage-mismatch -O3 -fomit-frame-pointer

/tools/gcc-4.7.3-0moz1/bin/g++     gcc version 4.7.3 (GCC)     -Wall -Wpointer-arith -Woverloaded-virtual -Werror=return-type -Wtype-limits -Wempty-body -Wsign-compare -Wno-invalid-offsetof -Wcast-align -fno-exceptions -fno-strict-aliasing -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions -std=gnu++0x -pthread -pipe -DNDEBUG -DTRIMMED -g -fprofile-use -fprofile-correction -Wcoverage-mismatch -O3 -fomit-frame-pointer

Configure arguments

--enable-update-channel=release --enable-update-packaging --with-google-api-keyfile=/builds/gapi.data --enable-elf-hack --enable-stdcxx-compat --enable-warnings-as-errors --enable-official-branding

Last edited by cfr (2013-10-03 01:57:34)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#12 2013-10-03 06:15:31

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,354

Re: Why is extra/firefox compiled with -O2 instead of -O3?

And here's one from a stock Firefox. Feel free to compare, I got bored.

Build Machine

Build platform
target
x86_64-unknown-linux-gnu
Build tools
Compiler 	Version 	Compiler flags
gcc 	gcc version 4.8.1 20130725 (prerelease) (GCC) 	-D_FORTIFY_SOURCE=2 -Wall -Wpointer-arith -Wdeclaration-after-statement -Werror=return-type -Wtype-limits -Wempty-body -Wsign-compare -Wno-unused -Wcast-align -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -std=gnu99 -fgnu89-inline -fno-strict-aliasing -ffunction-sections -fdata-sections -pthread -pipe -DNDEBUG -DTRIMMED -g -fprofile-use -fprofile-correction -Wcoverage-mismatch -O3 -fomit-frame-pointer
c++ 	gcc version 4.8.1 20130725 (prerelease) (GCC) 	-D_FORTIFY_SOURCE=2 -Wall -Wpointer-arith -Woverloaded-virtual -Werror=return-type -Wtype-limits -Wempty-body -Wsign-compare -Wno-invalid-offsetof -Wcast-align -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -fno-exceptions -fno-strict-aliasing -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions -std=gnu++0x -pthread -pipe -DNDEBUG -DTRIMMED -g -fprofile-use -fprofile-correction -Wcoverage-mismatch -O3 -fomit-frame-pointer -D_FORTIFY_SOURCE=2
Configure arguments

--enable-application=browser --prefix=/usr --libdir=/usr/lib --enable-official-branding --with-google-api-keyfile=/build/firefox/src/mozilla-release/google-api-key --with-system-nspr --with-system-nss --with-system-jpeg --with-system-zlib --with-system-bz2 --with-system-png --with-system-libevent --with-system-libvpx --enable-system-hunspell --enable-system-sqlite --enable-system-ffi --enable-system-pixman --enable-startup-notification --enable-pulseaudio --disable-crashreporter --disable-updater --disable-installer

Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#13 2013-10-03 11:49:43

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,390

Re: Why is extra/firefox compiled with -O2 instead of -O3?

krnlpk wrote:
kokoko3k wrote:

Does the webpages look the same?
In the past i noticed that too, but the fonts looked way better on arch.

They are absolutely the same, IMHO.

Yeah, they are the same.
However, firefox  packaged from mozilla comes with libraries provided by other arch packages:

nspr /usr/lib/libnspr4.so
nspr /usr/lib/libplc4.so
nspr /usr/lib/libplds4.so
nss /usr/lib/libfreebl3.so
nss /usr/lib/libnss3.so
nss /usr/lib/libnssckbi.so
nss /usr/lib/libnssdbm3.so
nss /usr/lib/libnssutil3.so
nss /usr/lib/libsmime3.so
nss /usr/lib/libsoftokn3.chk
nss /usr/lib/libsoftokn3.so
nss /usr/lib/libssl3.so

I don't know if they may lead to performance changes, but you could test by youself by deleting them from the firefox (packaged by moziila) dir. and see if it still feels faster.

-EDIT
Anyway, differences between build and configure flags are here:
https://docs.google.com/spreadsheet/pub … utput=html

-EDIT2:
somebody could explain why in the build switch there is -O2 AND -Os togheter?

Last edited by kokoko3k (2013-10-03 12:20:22)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#14 2013-10-03 15:30:23

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Why is extra/firefox compiled with -O2 instead of -O3?

Regarding font rendering - to use e.g. Infinality's infinitely-better rendering, firefox must be compiled with --enable-system-cairo

-O2 and -Os are mixed, because firefox's build scripts are trying to optimize (based on e.g. the gcc version), and it's convenient this way, since precedence is given to the option that appears last.

Offline

#15 2013-10-03 15:43:15

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,390

Re: Why is extra/firefox compiled with -O2 instead of -O3?

brebs wrote:

Regarding font rendering - to use e.g. Infinality's infinitely-better rendering, firefox must be compiled with --enable-system-cairo

We're a bit OT, but It doesn't seems so; my firefox (from extra) doesn't say it has been configured with --enable-system-cairo in about:buildconfig ; but it still uses my infinality settings (just tested with grip-git); maybe is it a default switch now...


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#16 2013-10-03 15:44:50

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Why is extra/firefox compiled with -O2 instead of -O3?

Offline

#17 2013-10-03 16:08:37

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,390

Re: Why is extra/firefox compiled with -O2 instead of -O3?

...that confuses me; nvidia blob had terrible performance in the past with cairo and firefox scrolled very bad; so that cairo-nvidia from aur fixed it.

EDIT:
Indeed, actually some libraries from firefox package are linked to system cairo:

# for file in $(pacman -Ql firefox|grep \.so|cut -d " " -f 2) ; do echo $file ; ldd $file |grep cairo; done 
/usr/lib/firefox/browser/components/libbrowsercomps.so
        libcairo.so.2 => /usr/lib/libcairo.so.2 (0xb3976000)
        libpangocairo-1.0.so.0 => /usr/lib/libpangocairo-1.0.so.0 (0xb3742000)
/usr/lib/firefox/components/libdbusservice.so
        libcairo.so.2 => /usr/lib/libcairo.so.2 (0xb399e000)
        libpangocairo-1.0.so.0 => /usr/lib/libpangocairo-1.0.so.0 (0xb36d2000)
/usr/lib/firefox/components/libmozgnome.so
        libcairo.so.2 => /usr/lib/libcairo.so.2 (0xb39b6000)
        libpangocairo-1.0.so.0 => /usr/lib/libpangocairo-1.0.so.0 (0xb36d2000)
/usr/lib/firefox/libmozalloc.so
/usr/lib/firefox/libxul.so
        libcairo.so.2 => /usr/lib/libcairo.so.2 (0xb3c6d000)
        libpangocairo-1.0.so.0 => /usr/lib/libpangocairo-1.0.so.0 (0xb3708000)

maybe i didn't fully understood what was that bug about.

Last edited by kokoko3k (2013-10-03 16:12:26)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#18 2013-10-03 17:20:45

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Why is extra/firefox compiled with -O2 instead of -O3?

Interesting. Perhaps the cairo that's bundled with firefox has been improved. It has quite a few patches applied.

kokoko3k wrote:

nvidia blob had terrible performance in the past with cairo and firefox scrolled very bad; so that cairo-nvidia from aur fixed it.

There's 2 patches that *I* apply to cairo:

1.  cairo-respect-fontconfig.patch, to properly apply fontconfig's rules.

2.  cairo-1.10.0-buggy_gradients.patch, to be faster with Nvidia's driver. This is in firefox 24.0's bundled cairo, in a slightly different format, as gfx/cairo/disable-server-gradients.patch - a snippet:

+    /* gradients don't seem to work */
+    display->buggy_gradients = TRUE;

Offline

#19 2013-10-03 23:33:05

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,131

Re: Why is extra/firefox compiled with -O2 instead of -O3?

The firefox I have from Mozilla uses system cairo - the library isn't included in Mozilla's bundle at all.

For both Arch's and Mozilla's build, it is the bundled libxul.so which is linked to the system cairo library.


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#20 2013-10-04 06:40:39

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,390

Re: Why is extra/firefox compiled with -O2 instead of -O3?

@Brebs:
I repeat: my firefox respects my infinality settings and renders the fonts exactly like any other app based on system cairo.
As for the gradient issue, i used to patch the cairo gradient function too until nvidia came up with a proper fix not so long ago.
As for cairo performance under nvidia, before the nvidia fix, just switching from the patched cairo to the system one made firefox scrolling jerky/smooth.
How would this be possible if firefox didn't used system cairo?


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#21 2013-10-04 07:57:59

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Why is extra/firefox compiled with -O2 instead of -O3?

Yeah, I've just checked myself, and Mozilla's firefox binary uses the system cairo, via libxul.so as cfr mentioned.

This surprises me.  --enable-system-cairo and --disable-system-cairo don't do what I would expect them to.

The firefox source code does not bundle all of cairo, since the gfx/cairo tree is only 8mb. The bundled cairo is a snapshot upto this commit, dated 2010-Jan-21.

This in an interesting command to run, in firefox's source code:

find -type f -print0 | xargs -0 grep MOZ_TREE_CAIRO

I'm surprised by why e.g. this conditional should exist, in gfx/thebes/gfxPlatform.cpp:

#if MOZ_TREE_CAIRO
    cairo_surface_t *nullSurf =
    cairo_null_surface_create(CAIRO_CONTENT_COLOR_ALPHA);
    cairo_surface_set_user_data(nullSurf,
                                &kSourceSurface,
                                imgSurface,
                                NULL);
    cairo_surface_attach_snapshot(imgSurface->CairoSurface(), nullSurf, SourceSnapshotDetached);
    cairo_surface_destroy(nullSurf);
#else
    cairo_surface_set_mime_data(imgSurface->CairoSurface(), "mozilla/magic", (const unsigned char*) "data", 4, SourceSnapshotDetached, imgSurface.get());
#endif

It's bizarre hmm

Offline

#22 2013-10-05 01:30:59

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,131

Re: Why is extra/firefox compiled with -O2 instead of -O3?

I agree that all seems weird. All I can repeat is, I'm using Mozilla's build and that uses system cairo (actually infinality's but would otherwise be Arch's).


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

Board footer

Powered by FluxBB