Should GHC default to -O1 ?

Conrad Parker conrad at metadecks.org
Wed Nov 9 03:00:07 CET 2011


On 9 November 2011 00:16, 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.

I don't think compile time is an issue for new users when building
HelloWorld.hs and getting the hang of basic algorithms and data
structures. Anyone could explicitly set -O0 if they are worried about
compile times for a larger project.

Having some optimizations on by default would help give new users a
better impression of how code written in Haskell performs. Currently
the first impression people have comes from seeing their code compiled
into the slowest version GHC can produce :)

Conrad.



More information about the Glasgow-haskell-users mailing list