Compiling with -O3

Mark Callaghan was just asking about what gcc compilation flags people use. (Not sure if Facebook Notes recognize pingbacks or not, so I sort of hope Mark is reading planetmysql, too)

Most of the distros build with -O2 (except for Gentoo, which compiles with as many flags as they can find) It's also the default in autoconf, the rationale being, I believe, that -O3 doesn't give discernable benefit for most things, but does require a considerably higher CPU cost during the compile. If you are, say, Debian, and you're compiling over 10k packages, streamlining the compile for the normal case is probably a great idea.

In Drizzle, however, we do override that default and build with -O3 at all times. I did some testing in our benchmark system about a month ago, mainly because I wanted to verify that -O3 was worth the extra effort that's in our autoconf files to do the override. I don't remember the exact numbers (I can re-run if someone really wants to know) but it was significant (something is telling me 25%) My next step was going to be compiling with -O2 and each of the individual optimizations that are in -O3 and not in -O2 to try to find out where the win was coming from. Haven't done it yet, though.

The original reason I bumped us to -O3 had nothing to do with performance though, oddly enough, it had to do with an increased set of warnings generated in some of the warning flags. Again, rather uselessly I do not remember the exact warning that gets generated only under -O3 (and I don't ever see if because we fixed it and moved on) but it's perhaps another reason why one should build free of compiler warnings - some of those "dangerous" constructs that the dev things the compiler is "wrong" about actually might be problematic at higher optimization levels. :)

9 Comments

  1. [1]   Mark Callaghan
    August 28, 2009 at 11:11 AM

    Thanks for the response. Was the 25% speedup on a benchmark mostly doing InnoDB page checksums? Or something else?
  2. [2]   Mark Callaghan
    August 28, 2009 at 11:24 AM

    And I am a faithful reader of planetmysql
  3. [3]   Jonas Oreland
    August 28, 2009 at 11:37 AM

    hrmf...i'm gentoo user and "only" have CFLAGS="-O2 -march=nocona"
  4. [4]   Twirrim
    August 28, 2009 at 03:01 PM

    I've heard, admittedly anecdotally, that O3 isn't suitable for total OS, but is for main programs run on it. It wasn't that the O3 wouldn't work for the OS, just that more often than not it resulted in larger files than O2 that therefore took longer to load than was necessary, usually offsetting any advantages gained from the O3.
  5. [5]   jsled
    August 28, 2009 at 04:07 PM

    :( While you will still find Gentoo ricers who do push the boundaries of compiler flags, that the exception, not the rule. The prevailing wisdom and advice from the project is to use <http://en.gentoo-wiki.com/wiki/Safe_Cflags>.
  6. [6]   http://topsy.com/tb/inaugust.com/post/65
    August 29, 2009 at 01:36 PM

  7. [7]   foo
    October 02, 2009 at 05:01 AM

    Also consider the following flags -march=native (newer gcc is now smart enough to figure out the correct flags per cpu arch) -fomit-frame-pointer -fstack-protector -D_FORTIFY_SOURCE=2
  8. [8]   tpetieog
    November 12, 2009 at 04:03 AM

    tpetieog
  9. [9]   http://www.google.com/search?q=zbqxacak
    November 12, 2009 at 04:03 AM

Comment on this post