Should GHC default to -O1 ?

David Fox ddssff at gmail.com
Tue Nov 8 17:49:26 CET 2011


On Tue, Nov 8, 2011 at 8:16 AM, Simon Marlow <marlowsd at gmail.com> wrote:
> On 08/11/2011 14:31, Daniel Fischer wrote:
>>
>> On the haskell-cafe as well as the beginners mailing lists, there
>> frequently (for some value of frequent) are posts where the author
>> inquires
>> about a badly performing programme, in the form of stack overflows, space
>> leaks or slowness.
>>
>> Often this is because they compiled their programme without optimisations,
>> simply recompiling with -O or -O2 yields a decently performing programme.
>>
>> So I wonder, should ghc compile with -O1 by default?
>> What would be the downsides?
>
> I understand the problem.  However, -O has a couple of serious downsides:
>
>  1. it costs about 2x compile time and memory usage
>
>  2. it forces a lot more recompilation to happen after changes,
>     due to inter-module optimisations.
>
> most people know about 1, but I think 2 is probably less well-known. When in
> the edit-compile-debug cycle it really helps to have -O off, because your
> compiles will be so much quicker due to both factors 1 & 2.
>
> So the default -O setting is a careful compromise, trying to hit a good
> compile-time/runtime tradeoff.  Perhaps we're more sensitive in Haskell
> because -O can easily give you an order of magnitude or more speedup,
> whereas in C you're likely to get a pretty consistent 30% or so.  The
> difference between -O and -O2 is another careful tradeoff.
>
> Also bear in mind that using GHCi gives you another 2x speedup in
> compilation (approx), but 30x slowdown in runtime (varies wildly from
> program to program though).  And subsequent recompiles are much faster
> because GHCi has cached a lot of interfaces.
>
> I suppose we should really run an up to date set of benchmarks on some real
> Haskell programs (i.e. not nofib) and reconsider how we set these defaults.
>  I really doubt that we'll want to turn on -O by default, though.

We should remember that we are only talking about which default leads
to the best outcome when, due to inexperience, someone fails to set
the option the way they want it.



More information about the Glasgow-haskell-users mailing list