
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? Roman NoFib Results -------------------------------------------------------------------------------- Program Size Allocs Runtime Elapsed -------------------------------------------------------------------------------- anna +2.5% -0.2% 0.08 0.11 ansi +0.0% +0.0% 0.00 0.01 atom +0.0% +0.0% 0.20 +0.0% awards +0.0% +0.0% 0.00 0.01 banner +0.0% +0.0% 0.00 0.01 bernouilli +0.0% +0.0% +0.0% +0.5% boyer +0.0% -0.3% 0.03 0.04 boyer2 +0.2% +0.0% 0.00 0.01 bspt +0.4% +0.0% 0.00 0.02 cacheprof +0.6% +0.0% +0.0% +0.0% calendar +0.2% +0.1% 0.00 0.01 cichelli +0.0% -0.0% 0.07 0.08 circsim +0.2% -0.0% -1.4% +0.3% clausify +0.2% -6.8% 0.03 0.04 comp_lab_zift +0.8% +0.7% 0.17 0.19 compress +0.0% +0.0% 0.14 0.16 compress2 +2.3% -1.3% 0.14 0.17 constraints +0.0% +0.0% -0.4% -0.0% cryptarithm1 +0.0% +0.0% +0.0% -0.3% cryptarithm2 +0.0% -4.7% 0.01 0.02 cse +0.0% +0.0% 0.00 0.01 eliza +0.0% +0.0% 0.00 0.01 event +0.2% +1.5% 0.14 0.16 exp3_8 +0.0% +0.0% 0.10 0.11 expert +0.4% +0.4% 0.00 0.01 fem +0.5% +1.0% 0.02 0.02 fft +0.2% -1.6% 0.03 0.04 fft2 +0.2% +0.0% 0.06 0.07 fibheaps +0.2% +0.4% 0.03 0.04 fish +0.0% +0.0% 0.01 0.03 fluid +2.1% -1.9% 0.01 0.02 fulsom +0.2% +0.0% +0.0% -0.5% gamteb +0.7% -2.1% 0.07 0.09 gcd +0.0% -1.7% 0.02 0.02 gen_regexps +0.0% +0.0% 0.00 0.01 genfft +0.0% -0.3% 0.03 0.03 gg +0.5% -0.8% 0.01 0.02 grep +0.2% +0.0% 0.00 0.01 hidden +0.3% +0.0% -3.2% -3.5% hpg +0.2% +0.0% 0.14 +0.6% ida +0.5% -0.7% 0.07 0.08 infer +0.0% +0.0% 0.04 0.05 integer +0.0% +0.0% +0.0% +0.0% integrate +0.0% +0.0% +0.0% +0.0% knights +0.7% -13.4% 0.00 0.01 lcss +0.0% -0.0% -0.8% -0.7% life +0.0% +0.0% 0.20 -1.0% lift +0.2% +3.6% 0.00 0.01 listcompr +0.0% +0.0% 0.09 0.12 listcopy +0.0% -0.0% 0.10 0.13 maillist +0.0% -0.2% 0.05 +0.2% mandel +0.0% +0.0% 0.07 0.09 mandel2 +0.2% -67.2% 0.00 0.00 minimax +0.0% +0.4% 0.00 0.01 mkhprog +0.0% +0.0% 0.00 0.01 multiplier +0.0% +0.0% 0.09 0.11 nucleic2 +0.0% +0.0% 0.06 0.07 para +0.9% +0.5% +6.4% +5.5% paraffins +0.4% +0.2% 0.07 0.10 parser +0.5% +0.3% 0.03 0.04 parstof +0.2% -2.5% 0.00 0.01 pic +0.4% -0.8% 0.00 0.02 power +0.4% +0.0% +0.0% +0.8% pretty +0.2% -2.9% 0.00 0.01 primes +0.0% +0.0% 0.05 0.06 primetest +0.2% +0.0% +0.0% +0.6% prolog +0.2% -0.9% 0.00 0.01 puzzle +0.0% +0.0% 0.14 0.16 queens +0.0% -72.0% 0.01 0.02 reptile +0.2% +0.0% 0.01 0.02 rewrite +0.2% +0.0% 0.01 0.02 rfib +0.0% +0.0% 0.04 0.05 rsa +0.0% +0.0% 0.06 0.07 scc +0.0% +0.0% 0.00 0.01 sched +0.2% +0.6% 0.02 0.03 scs +0.8% -0.4% +0.0% +1.4% simple +0.2% +0.0% +0.0% +0.0% solid +0.0% -0.0% 0.11 0.13 sorting +0.2% +0.0% 0.00 0.01 sphere +0.0% +0.5% 0.08 0.09 symalg +0.5% -0.0% 0.03 0.04 tak +0.0% +0.0% 0.01 0.02 transform +0.6% -0.0% +0.0% +0.7% treejoin +0.2% -2.0% 0.20 +3.5% typecheck +0.0% +0.3% 0.19 +0.0% veritas +1.0% -0.3% 0.00 0.01 wang +0.0% -1.0% 0.07 0.09 wave4main +0.0% +0.0% +3.7% +1.4% wheel-sieve1 +0.2% +0.0% +0.0% -0.8% wheel-sieve2 +0.2% +0.0% 0.14 0.17 x2n1 +0.0% -1.3% 0.02 0.03 -------------------------------------------------------------------------------- Min +0.0% -72.0% -3.2% -3.5% Max +2.5% +3.6% +6.4% +5.5% Geometric Mean +0.2% -3.0% +0.2% +0.4%

On 05/05/2010 12:24, 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).
What were the compile-time results? We really need to bump all the runtimes in nofib or switch to using Criterion. The runtime figures are pretty useless. Note that you can run with 'make mode=slow' which will use larger inputs for some, but not all, of the programs.
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?
Maybe, let's see what the compile times are like. Cheers, Simon

On 07/05/2010, at 19:53, Simon Marlow wrote:
On 05/05/2010 12:24, 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).
What were the compile-time results?
Gosh, I thought I included those. -1 s.d. ----- +1.1% +1 s.d. ----- +16.3% Average ----- +8.4% The full results are below. IMO, the increases are rather negligible. Roman Compile Times ------------------------------------------------------------------------------- Program log-O log-O2 ------------------------------------------------------------------------------- anna AbsConc3 0.23 +17.4% AbstractEval2 0.08 0.08 AbstractMisc 0.11 0.12 AbstractVals2 0.23 +17.4% Apply 0.10 0.12 BarakiConc3 0.17 0.18 BarakiMeet 0.11 0.12 BaseDefs 0.87 +8.0% Constructors 0.17 0.21 Dependancy 0.24 +25.0% DomainExpr 0.12 0.13 EtaAbstract 0.12 0.13 FrontierDATAFN2 0.19 0.19 FrontierGENERIC 0.16 0.16 FrontierMisc2 0.10 0.11 Inverse 0.16 0.16 LambdaLift5 0.42 +4.8% Main 0.31 +0.0% MakeDomains 0.10 0.10 Monster 0.12 0.12 MyUtils 0.13 0.13 Parser2 0.64 +7.8% PrettyPrint 0.13 0.13 PrintResults 0.23 +8.7% ReadTable 0.16 0.17 Simplify 0.10 0.10 SmallerLattice 0.36 +13.9% StrictAn6 0.59 +11.9% SuccsAndPreds2 0.24 +4.2% TExpr2DExpr 0.10 0.10 TypeCheck5 0.70 +14.3% Utils 0.34 +14.7% ansi Main 0.20 0.20 atom Main 0.16 0.16 awards Main 0.16 0.16 QSort 0.04 0.05 banner Main 0.29 +3.4% bernouilli Main 0.15 0.15 boyer Main 0.42 +4.8% boyer2 Checker 0.06 0.07 Lisplikefns 0.15 0.16 Main 0.08 0.08 Rewritefns 0.07 0.09 Rulebasetext 0.11 0.12 bspt BSPT 0.20 0.23 Euclid 0.32 +3.1% EuclidGMS 0.15 0.16 GeomNum 0.11 0.11 Init 0.13 0.13 Input 0.40 +5.0% Interface 0.10 0.10 Interpret 0.12 0.13 Libfuns 0.03 0.03 MGRlib 0.09 0.09 Main 0.06 0.06 Merge 0.13 0.14 Params 0.09 0.09 Prog 0.06 0.06 Rationals 0.18 0.19 Render 0.12 0.12 Stdlib 0.09 0.10 cacheprof Arch_x86 0.68 +2.9% Generics 0.19 0.20 Main 2.13 +11.3% calendar Main 0.24 +8.3% cichelli Auxil 0.15 0.17 Interval 0.03 0.03 Key 0.04 0.04 Main 0.05 0.05 Prog 0.12 0.12 circsim Main 0.63 +7.9% clausify Main 0.23 +4.3% comp_lab_zift Main 0.68 +20.6% compress BinConv 0.09 0.09 BinTest 0.08 0.08 Decode 0.16 0.16 Defaults 0.05 0.05 Encode 0.14 0.16 Main 0.06 0.06 PTTrees 0.04 0.04 Uncompress 0.07 0.07 compress2 Encode 0.14 0.39 Main 0.08 0.08 WriteRoutines 0.10 0.12 constraints Main 0.34 +8.8% cryptarithm1 Main 0.09 0.09 cryptarithm2 Main 0.22 +13.6% MonadState 0.10 0.10 MonadTrans 0.03 0.03 cse Main 0.25 +4.0% StateMonad 0.07 0.07 eliza Main 0.39 +2.6% event Main 0.30 +10.0% exp3_8 Main 0.15 0.15 expert Knowledge 0.11 0.11 Main 0.15 0.15 Match 0.06 0.07 Result 0.04 0.04 Search 0.09 0.10 Table 0.14 0.17 fem Assemble_loadve 0.07 0.07 Assemble_stiffn 0.10 0.12 Basics 0.06 0.06 DB_interface 0.14 0.15 Database 0.13 0.14 Degrees 0.17 0.19 Displacement 0.09 0.09 Elemforce 0.07 0.07 Elemstif 0.09 0.10 Main 0.06 0.06 Matrix 0.18 0.20 Pre_assemble 0.08 0.08 PrintSource 0.19 0.19 Printuvwforce 0.09 0.09 VBlldecomp 0.15 0.17 VBmatrix 0.16 0.17 Vector 0.13 0.15 fft Main 0.45 +13.3% fft2 Complex_Vectors 0.08 0.08 Fourier 0.18 0.20 Main 0.13 0.13 fibheaps Main 0.35 +8.6% fish Main 0.37 +2.7% fluid Asb_routs 0.10 0.10 C_matrix 0.16 0.16 Chl_decomp 0.18 0.24 Chl_method 0.20 0.22 Chl_routs 0.37 +51.4% Defs 0.03 0.03 Elefac 0.07 0.08 Input_proc 0.28 +32.1% Jcb_method 0.16 0.17 L_matrix 0.07 0.08 Main 0.08 0.09 Min_degree 0.12 0.14 Norm 0.07 0.07 Rhs_Asb_routs 0.16 0.17 S_Array 0.50 +18.0% S_matrix 0.15 0.15 TG_iter 0.22 +0.0% Tol_cal 0.06 0.07 fulsom Csg 0.29 +3.4% Interval 0.30 +6.7% Kolor 0.17 0.17 Main 0.11 0.11 Matrix 0.17 0.18 Oct 0.11 0.11 Patchlevel 0.03 0.03 Quad 0.10 0.11 Raster 0.13 0.13 Shapes 0.07 0.08 Types 0.19 0.21 Vector 0.08 0.08 gamteb Compton 0.11 0.11 Consts 0.05 0.05 Distance 0.10 0.13 GamtebMain 0.07 0.07 GamtebType 0.03 0.03 InitTable 0.14 0.15 Main 0.07 0.07 Output 0.15 0.16 Pair 0.08 0.08 PhotoElec 0.06 0.06 RoulSplit 0.06 0.06 TransPort 0.12 0.12 Utils 0.15 0.20 gcd Main 0.13 0.14 gen_regexps Main 0.13 0.13 genfft Main 0.40 +5.0% gg Activity 0.17 0.19 GRIP 0.33 +0.0% Graph 0.40 +12.5% Main 0.21 +0.0% PSlib 0.23 +0.0% Parse 0.10 0.10 Pool 0.13 0.14 Spark 0.15 0.16 StdLib 0.11 0.12 grep Main 0.29 +10.3% Parsers 0.09 0.09 StringMatch 0.25 +4.0% hidden Comparing 0.12 0.14 Cross 0.08 0.08 EdgePlate 0.06 0.06 Geometric 0.11 0.11 Hide 0.11 0.13 Main 0.07 0.07 Matrices 0.03 0.03 Memo 0.39 +7.7% MyIO 0.09 0.09 Numbers 0.13 0.13 Postscript 0.07 0.07 Preds 0.08 0.08 Rotate 0.06 0.06 Solve 0.08 0.08 Vectors 0.14 0.14 hpg Config 0.07 0.07 Env 0.17 0.17 GenExp 0.25 +4.0% GenType 0.11 0.11 GenVal 0.11 0.11 Main 0.26 +3.8% Types 0.32 +9.4% Utils 0.07 0.07 ida Main 0.39 +23.1% infer Environment 0.12 0.12 FiniteMap 0.08 0.08 Infer 0.09 0.10 InferMonad 0.11 0.11 Main 0.11 0.11 MaybeM 0.04 0.04 MyList 0.04 0.04 Parse 0.15 0.15 Shows 0.05 0.05 State 0.04 0.04 StateX 0.05 0.05 Substitution 0.08 0.08 Term 0.17 0.18 Type 0.17 0.18 integer Main 0.15 0.15 integrate Main 0.15 0.15 knights ChessSetArray 0.24 +8.3% ChessSetList 0.17 0.19 KnightHeuristic 0.12 0.18 Main 0.15 0.15 Queue 0.06 0.06 Sort 0.10 0.10 lcss Main 0.16 0.16 life Main 0.14 0.15 lift LambdaLift 0.38 +10.5% Main 0.07 0.07 Print 0.19 0.20 Test 0.08 0.08 Utilities 0.12 0.13 listcompr Main 0.33 +3.0% listcopy Main 0.33 +3.0% maillist Main 0.17 0.20 mandel Main 0.12 0.12 Mandel 0.12 0.12 PortablePixmap 0.06 0.06 mandel2 Main 0.19 0.22 minimax Board 0.16 0.17 Game 0.10 0.10 Main 0.05 0.05 Prog 0.04 0.04 Tree 0.07 0.07 Wins 0.04 0.04 mkhprog Main 0.35 +2.9% multiplier Main 0.51 +3.9% nucleic2 Main 0.60 +1.7% RA 0.44 +4.5% RC 0.43 +4.7% RG 0.18 0.18 RU 0.46 +4.3% Types 0.03 0.03 para Main 0.66 +24.2% paraffins Main 0.28 +17.9% parser Main 1.75 +15.4% parstof Main 2.80 +6.8% pic ChargeDensity 0.08 0.08 Consts 0.04 0.04 ElecField 0.13 0.15 Main 0.07 0.07 Pic 0.10 0.10 PicType 0.03 0.03 Potential 0.15 0.16 PushParticle 0.12 0.13 Utils 0.29 +10.3% power Main 0.46 +10.9% pretty CharSeq 0.06 0.08 Main 0.07 0.07 Pretty 0.15 0.17 primes Main 0.11 0.12 primetest IntLib 0.09 0.09 Main 0.07 0.08 MyRandom 0.06 0.06 Prime 0.12 0.15 prolog Engine 0.06 0.08 Interact 0.07 0.08 Main 0.18 0.18 Parse 0.09 0.10 PrologData 0.22 +4.5% Subst 0.08 0.08 Version 0.03 0.03 puzzle Main 0.30 +10.0% queens Main 0.11 0.12 reptile Auxprogfuns 0.28 +7.1% Diff 0.06 0.06 Drawfuns 0.10 0.10 Geomfuns 0.14 0.14 Help 0.11 0.11 Interstate 0.03 0.03 Layout 0.31 +6.5% Main 0.07 0.08 Mgrfuns 0.10 0.10 Progfuns 0.46 +4.3% Psfuns 0.09 0.09 Rational 0.09 0.10 Tilefuns 0.15 0.16 rewrite Main 0.61 +4.9% rfib Main 0.10 0.10 rsa Main 0.09 0.09 Rsa 0.12 0.12 scc Digraph 0.05 0.05 Main 0.07 0.07 sched Main 0.37 +8.1% scs LinearAlgebra 0.60 +35.0% Main 0.17 0.18 Parse 0.29 +3.4% ParseLib 0.14 0.15 RandomFix 0.10 0.11 Simulate 0.54 +16.7% Types 0.09 0.09 simple Main 3.46 +11.3% solid Main 1.89 +0.5% sorting Main 0.08 0.08 Sort 0.16 0.18 sphere Main 0.69 +14.5% symalg Ast 0.03 0.03 BasicNumber 0.27 +0.0% BasicNumberAppr 0.13 0.14 Env 0.05 0.05 Eval 0.13 0.14 Lexer 0.10 0.10 Main 0.10 0.10 Op 0.07 0.08 Parser 0.14 0.19 Print 0.12 0.12 RealM 0.20 0.20 tak Main 0.10 0.10 transform Main 1.58 +11.4% treejoin Main 0.17 0.19 typecheck Main 0.51 +7.8% veritas Attributes 0.05 0.05 Auto 0.07 0.07 Build_Tm 0.16 0.16 Build_itrm 0.23 +0.0% Core_database 0.54 +11.1% Core_datatype 0.12 0.12 Dcore 0.09 0.09 DerivedRules 0.14 0.16 Display 0.30 -3.3% Editor 0.09 0.09 Edlib 0.12 0.12 Getops 0.07 0.07 Globals 0.05 0.05 Goals 0.27 +11.1% Kernel 0.70 +1.4% Lookup 0.03 0.03 Main 0.29 +3.4% Parse 0.91 +16.5% Sub_Core1 0.24 +4.2% Sub_Core2 0.19 0.20 Sub_Core3 0.18 0.19 Sub_Core4 0.25 +4.0% Tacticals 0.10 0.10 Tactics 0.19 0.20 Tags 0.07 0.07 ThmTactics 0.66 +6.1% Token 0.15 0.17 Tree 0.17 0.18 Type_defs 0.07 0.07 Unparse 0.32 +9.4% Vtslib 0.06 0.06 X_interface 0.41 +4.9% wang Main 0.34 +5.9% wave4main Main 0.51 +0.0% wheel-sieve1 Main 0.16 0.18 wheel-sieve2 Main 0.16 0.18 x2n1 Main 0.12 0.13 -1 s.d. ----- +1.1% +1 s.d. ----- +16.3% Average ----- +8.4%

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

duncan.coutts:
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.
+1 It might be a good time to revise the set of "balanced" optimizations available at -O1 (-O) level.

Hello Duncan, Sunday, May 9, 2010, 1:50:31 AM, you wrote:
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
cloning gcc policy may be a good choice. -O2 is the best optimization that "guaranteed" to make program faster and -O3 is for speculative optimization (those that may be breaked by unusual code or made program slower). not sure about -O1, may be difference is that -O1 or just -O is "development-time" optimization, i.e. quick&dirty and -O2 generates production code -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

* Bulat Ziganshin:
cloning gcc policy may be a good choice. -O2 is the best optimization that "guaranteed" to make program faster and -O3 is for speculative optimization (those that may be breaked by unusual code or made program slower). not sure about -O1,
-O1 is supposed to yield somewhat optimized code with very good debugging information. Quality of debugging information at -O2 was really abysmal for a while, but it should be improving again.

On 09/05/2010, at 07:50, Duncan Coutts wrote:
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.
Unless I'm mistaken, the only difference between -O1 and -O2 are SpecConstr and LiberateCase. These are quite heavily constrained by default (e.g., SpecConstr will not specialise big functions and will not generate more than 3 specialisations for smaller ones).
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.
And yet that doesn't really happen for nofib programs. So if there are still examples of this, we should include them in nofib. Quite probably, they're just running into bugs in the simplifier which should be fixed. Also, the Cabal warning only talks about compile times. If it's just between compile times and better performance, then the latter should be the default, IMO, since you only install things once and run them many times. Roman

On 10/05/2010 03:43, Roman Leshchinskiy wrote:
On 09/05/2010, at 07:50, Duncan Coutts wrote:
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.
Unless I'm mistaken, the only difference between -O1 and -O2 are SpecConstr and LiberateCase. These are quite heavily constrained by default (e.g., SpecConstr will not specialise big functions and will not generate more than 3 specialisations for smaller ones).
I'd like to keep a distinction between -O1 and -O2, but I agree with you that we could probably look at how the optimisations are currently distributed between the options. We could probably also add a -O3 that turns up various thresholds for people who don't mind generating larger code. -O1 is supposed to represent good value for compile-time. It gets all the low-hanging fruit. I use -O in my development builds, whereas it makes sense for Cabal to turn on -O2 by default and for us to use -O2 for the nightly builds and when building GHC distributions (we already do this). Cheers, Simon
participants (6)
-
Bulat Ziganshin
-
Don Stewart
-
Duncan Coutts
-
Florian Weimer
-
Roman Leshchinskiy
-
Simon Marlow