cabal sdist warns about optimization levels

Hi all, I'm working on a library for fast sorting of MArrays. The library is primarily about speed, so I added ghc-options: -O2 to the cabal file. Now cabal sdist complains with: 'ghc-options: -O2' is rarely needed. Check that it is giving a real benefit and not just imposing longer compile times on your users. I wonder: (1) Is there a way how to disable the warning? As the main aim of the library is speed, I believe -O2 is appropriate here. And since the code is quite short, I'm quite sure the increased compile time won't be noticeable. (2) Why does cabal complain about it at the first place? I found a reference saying the warning is adequate: https://github.com/haskell/cabal/issues/808 but not saying why. Maybe for complex programs -O2 prolongs compile time too much, but libraries are usually compiled once and used many times, so using -O2 for them seems reasonable in many cases. Thanks for help, Petr Pudlak

On Sunday 13 January 2013, 21:27:44, Petr P wrote:
I wonder:
(1) Is there a way how to disable the warning? As the main aim of the library is speed, I believe -O2 is appropriate here. And since the code is quite short, I'm quite sure the increased compile time won't be noticeable.
(2) Why does cabal complain about it at the first place? I found a reference saying the warning is adequate: https://github.com/haskell/cabal/issues/808 but not saying why. Maybe for complex programs -O2 prolongs compile time too much, but libraries are usually compiled once and used many times, so using -O2 for them seems reasonable in many cases.
Sometimes compiling with -O2 instead of just -O takes significantly longer. Not always is the produced result faster (often, the results are identical). So if the code produced with -O performs equally to that produced with -O2, and the -O2 compilation takes significantly longer, choosing -O2 imposes a cost for no benefit. That's, I think, why the warning is considered adequate. You can specify -O2 on a per-module basis with an {-# OPTIONS_GHC -O2 #-} pragma where it matters, then cabal won't complain. Or, if you're too lazy to check the consequences of -O2 vs. -O for each module (like I usually am, if there are more than a handful), just verify that -O2 does indeed make a significant difference for the speed of the result in some places without increasing compile time unduly, and henceforth ignore the warning if it does. (Re-test every couple of compiler versions.) After some time, you tend to not even notice it anymore ;) Cheers, Daniel

On 13 January 2013 20:27, Petr P
to the cabal file. Now cabal sdist complains with:
'ghc-options: -O2' is rarely needed. Check that it is giving a real benefit and not just imposing longer compile times on your users.
I wonder:
(1) Is there a way how to disable the warning? As the main aim of the library is speed, I believe -O2 is appropriate here. And since the code is quite short, I'm quite sure the increased compile time won't be noticeable.
No, but you can just ignore it. You clearly have checked and you're satisfied it's the right thing to do, so it's fine. You don't need to hit 0 warnings, nobody is going to give you or your package black marks becuase of it! :-)
(2) Why does cabal complain about it at the first place?
There's lots of programs where it makes no measurable difference except to make compile times longer. To some extent it's to try to break the habbit of C programmers who always default to -O2. With gcc -O2 will almost always be significantly better than -O, but with ghc that's not the case: -O is the sensible default (almost by definition, to a first approximation, things that are always a win get put into -O, things that are sometimes a win and sometimes not go into -O2). Duncan
participants (3)
-
Daniel Fischer
-
Duncan Coutts
-
Petr P