-O vs. -O2

On Wed, 2010-05-05 at 21:24 +1000, Roman Leshchinskiy wrote:
> Whenever I do cabal sdist on one of my projects, I get this warning:
>> Distribution quality warnings:
> 'ghc-options: -O2' is rarely needed. Check that it is giving a real benefit
> and not just imposing longer compile times on your users.
>> This finally got me curious and I did a nofib run to compare -O to
> -O2. The results are below (this is with the current HEAD).
>> Is there a real-world example of -O2 causing significantly longer
> compile times without providing a real benefit? If not, would it
> perhaps make sense for Cabal to use -O2 by default or even for GHC to
> make the two flags equivalent?
It should be -O1 for default/balanced optimisations and -O2 for things
involving a bigger tradeoff in terms of code size or compile time. so
any optimisations in -O2 that GHC HQ believe are a no-brainer for the
majority of packages should be moved into -O1.
It's fine for people writing performance sensitive code to use -O2 in
their packages. It's just not something we need to encourage for random
packages. Before we added that warning, many package authors were not
really thinking and just chucking in -O2 "because 2 is bigger than 1 so
it must be better right?". There certainly used to be packages that took
longer to compile, generated more code, and ran slower when using -O2.
That was some time ago of course.
Duncan