Should GHC default to -O1 ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Should GHC default to -O1 ?

Daniel Fischer
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?

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

David Fox-7
On Tue, Nov 8, 2011 at 6:31 AM, Daniel Fischer
<[hidden email]> 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 think this is an excellent idea.  Even better -O2.

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

Johan Tibell-2
On Tue, Nov 8, 2011 at 7:11 AM, David Fox <[hidden email]> wrote:
On Tue, Nov 8, 2011 at 6:31 AM, Daniel Fischer
<[hidden email]> 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 think this is an excellent idea.  Even better -O2.

FWIW gcc defaults to -O0.


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

Simon Marlow-7
In reply to this post by Daniel Fischer
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.

Cheers,
        Simon

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

Sean Leather
In reply to this post by Daniel Fischer
On Tue, Nov 8, 2011 at 15:31, Daniel Fischer wrote:
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?

Previous discussion on this topic:

Regards,
Sean

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

David Fox-7
In reply to this post by Simon Marlow-7
On Tue, Nov 8, 2011 at 8:16 AM, Simon Marlow <[hidden email]> 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.

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

Daniel Fischer
In reply to this post by Simon Marlow-7
On Tuesday 08 November 2011, 17:16:27, Simon Marlow wrote:
> 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.

Of course. So defaulting to -O1 would mean one has to specify -O0 in the
.cabal or Makefile resp. on the command line during development, which
certainly is an inconvenience.

>
> 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,

It can even make the difference between a smoothly running programme and a
dying one, if one is naively using the right (wrong) constructs.

So the nub of the question is, which downside is worse?

My experience is limited, so I haven't sufficient data to form a reasoned
opinion on that, hence I ask.

> whereas in C you're likely to get a pretty consistent 30% or so.  The
> difference between -O and -O2 is another careful tradeoff.
>

>
> 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 suppose there are no cheap but effective optimisations one could move to
the default behaviour, or that would've been done :(


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

Felipe Lessa
On Tue, Nov 8, 2011 at 3:01 PM, Daniel Fischer
<[hidden email]> wrote:
> On Tuesday 08 November 2011, 17:16:27, Simon Marlow wrote:
>> 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.
>
> Of course. So defaulting to -O1 would mean one has to specify -O0 in the
> .cabal or Makefile resp. on the command line during development, which
> certainly is an inconvenience.

AFAIK, Cabal already uses -O1 by default.

Cheers,

--
Felipe.

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

Conrad Parker
In reply to this post by Simon Marlow-7
On 9 November 2011 00:16, Simon Marlow <[hidden email]> 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.

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

wagnerdm@seas.upenn.edu
Quoting Conrad Parker <[hidden email]>:

> 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.

I don't agree that GHC's user interface should be optimized for  
newcomers to Haskell. GHC is an industrial-strength compiler with some  
very advanced features; the majority of its target audience is  
professional programmers. Let its interface reflect that fact.

As Simon explained, GHC's current defaults are a very nice point in  
the programming space for people who are actively building and  
changing their programs.

~d

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

Nathan Howell-2
On Tue, Nov 8, 2011 at 11:28 PM, <[hidden email]> wrote:
I don't agree that GHC's user interface should be optimized for newcomers to Haskell. GHC is an industrial-strength compiler with some very advanced features; the majority of its target audience is professional programmers. Let its interface reflect that fact.

As Simon explained, GHC's current defaults are a very nice point in the programming space for people who are actively building and changing their programs.

It's easy to build arguments for either side, but my experience as a professional developer is that new devs don't know what arguments they need for reasonable performance, often knowing even what various optimization flags do, but experienced developers do know the difference between -O0 and -O1, and frequently need -debug (not a default option) more than -O0.

Seasoned GHC users can find that -O0 gives miserably slow compile times, and fall back to GHCi for edit/rebuild cycles... which still aren't terribly fast if you're using GHC's advanced features. I have a couple small modules that take 10 minutes each to compile on a current Core i7 at -O0, and -O2 really doesn't take much longer. GHCi is very slightly faster but I'll still head directly downstairs for a coffee as soon as either of these bad boys need rebuilding... and still make it back upstairs before they're done.

And so I'd prefer the default to be -O1 or even -O2 and have people who really need it use -O0. GHC shouldn't be painful on purpose, industrial strength or not.

-n

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

Duncan Coutts-4
In reply to this post by Felipe Lessa
On 9 November 2011 00:17, Felipe Almeida Lessa <[hidden email]> wrote:

> On Tue, Nov 8, 2011 at 3:01 PM, Daniel Fischer
> <[hidden email]> wrote:
>> On Tuesday 08 November 2011, 17:16:27, Simon Marlow wrote:
>>> 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.
>>
>> Of course. So defaulting to -O1 would mean one has to specify -O0 in the
>> .cabal or Makefile resp. on the command line during development, which
>> certainly is an inconvenience.
>
> AFAIK, Cabal already uses -O1 by default.

Indeed, and cabal check / hackage upload complain if you put -O{n} in
your .cabal file.

The recommended method during development is to use:

$ cabal configure -O0


Duncan

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

Greg Weber
How much does using ghc without cabal imply a newer programmer? I don't use cabal when trying out small bits of code (maybe I should be using ghci), but am otherwise always using cabal.

On Wed, Nov 9, 2011 at 3:18 AM, Duncan Coutts <[hidden email]> wrote:
On 9 November 2011 00:17, Felipe Almeida Lessa <[hidden email]> wrote:
> On Tue, Nov 8, 2011 at 3:01 PM, Daniel Fischer
> <[hidden email]> wrote:
>> On Tuesday 08 November 2011, 17:16:27, Simon Marlow wrote:
>>> 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.
>>
>> Of course. So defaulting to -O1 would mean one has to specify -O0 in the
>> .cabal or Makefile resp. on the command line during development, which
>> certainly is an inconvenience.
>
> AFAIK, Cabal already uses -O1 by default.

Indeed, and cabal check / hackage upload complain if you put -O{n} in
your .cabal file.

The recommended method during development is to use:

$ cabal configure -O0


Duncan

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Should GHC default to -O1 ?

Duncan Coutts-4
On 9 November 2011 13:53, Greg Weber <[hidden email]> wrote:
> How much does using ghc without cabal imply a newer programmer? I don't use
> cabal when trying out small bits of code (maybe I should be using ghci), but
> am otherwise always using cabal.

The main reason cabal has always defaulted to -O is because
historically it's been assumed that the user is installing something
rather than just hacking on their own code.

If we can distinguish cleanly in the user interface between the
installing and hacking use cases then we could default to -O0 for the
hacking case.

Duncan

> On Wed, Nov 9, 2011 at 3:18 AM, Duncan Coutts <[hidden email]>
> wrote:
>>
>> On 9 November 2011 00:17, Felipe Almeida Lessa <[hidden email]>
>> wrote:
>> > On Tue, Nov 8, 2011 at 3:01 PM, Daniel Fischer
>> > <[hidden email]> wrote:
>> >> On Tuesday 08 November 2011, 17:16:27, Simon Marlow wrote:
>> >>> 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.
>> >>
>> >> Of course. So defaulting to -O1 would mean one has to specify -O0 in
>> >> the
>> >> .cabal or Makefile resp. on the command line during development, which
>> >> certainly is an inconvenience.
>> >
>> > AFAIK, Cabal already uses -O1 by default.
>>
>> Indeed, and cabal check / hackage upload complain if you put -O{n} in
>> your .cabal file.
>>
>> The recommended method during development is to use:
>>
>> $ cabal configure -O0
>>
>>
>> Duncan
>>
>> _______________________________________________
>> Glasgow-haskell-users mailing list
>> [hidden email]
>> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
>

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users