Skip to content

Confusing -O1 in build profile #6221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sjakobi opened this issue Sep 1, 2019 · 30 comments
Open

Confusing -O1 in build profile #6221

sjakobi opened this issue Sep 1, 2019 · 30 comments

Comments

@sjakobi
Copy link
Member

sjakobi commented Sep 1, 2019

$ cabal build
Resolving dependencies...
Build profile: -w ghc-8.8.1 -O1
In order, the following will be built (use -v for more details):
 - bsb-http-chunked-0.0.0.4 (lib) (first run)

What does the -O1 in the Build profile: line mean? The ghc-options for my library component include -O2, and the verbose log shows that ghc is invoked with -O2 too.

@23Skidoo
Copy link
Member

23Skidoo commented Sep 1, 2019

It means that the local packages in the project are configured with -O1. However, as you correctly notice, this can be overridden on per-component basis in ghc-options.

@sjakobi
Copy link
Member Author

sjakobi commented Sep 1, 2019

Ah, thanks! In my case there weren't any other local packages that could be configured with -O1.

I first noticed it while benchmarking where it caused me much doubt about the validity of the numbers I was seeing.

What's the motivation for outputting this default(?) setting, especially when it doesn't apply / is overridden?

@phadej
Copy link
Collaborator

phadej commented Sep 1, 2019 via email

@sjakobi
Copy link
Member Author

sjakobi commented Sep 1, 2019

The motivation is that we consider ghc-options: -O2 (any -O flag) to be at the very least questionable practice.

Interesting! Was there some kind of discussion that I could read?

Configuring the optimization level like this seems useful. Reporting -O1, when the actual optimization level applied is different, still seems confusing to me. Maybe cabal should also report the overrides then…

@jberryman
Copy link

I guess I'm not following the back and forth here.

It means that the local packages in the project are configured with -O1.

I have a project where I have a cabal.project.local that looks like:

package our-project
  optimization: 0
  documentation: false

and a .cabal file like:

name:                our-project
library
   ...
executable our-project
  ...
  • When I do a new-build I see Build profile: -w ghc-8.6.5 -O1
  • If I move optimization: 0 to the top-level I see ``Build profile: -w ghc-8.6.5 -O0`
  • In both cases it looks like the library and executable in my project are built without optimizations (as intended)

So I'm not sure what "Build profile" is supposed to mean, and not sure if what it's reporting is correct, and not sure if I'm using my cabal.project.local file correctly

Related to #5353

@phadej
Copy link
Collaborator

phadej commented Jan 22, 2020 via email

@tomjaguarpaw
Copy link
Member

What does the -O1 in the Build profile: line mean? The ghc-options for my library component include -O2, and the verbose log shows that ghc is invoked with -O2 too.

FYI I have also just experienced puzzlement at this.

@fgaz
Copy link
Member

fgaz commented Sep 26, 2021

I think it's the "global" optimization level, ie. the top-level optimization: in cabal.project.

@jneira
Copy link
Member

jneira commented Sep 26, 2021

and what about include that useful info in the message, something like Top level build profile...

@fgaz
Copy link
Member

fgaz commented Sep 26, 2021

@sjakobi @jberryman @tomjaguarpaw is @jneira's proposal enough to clarify the meaning of that message? If not, any suggestions?

@tomjaguarpaw
Copy link
Member

Well, it would certainly be better (and give something more substantial to Duck Duck Go for when confused).

@sjakobi
Copy link
Member Author

sjakobi commented Sep 27, 2021

is @jneira's proposal enough to clarify the meaning of that message? If not, any suggestions?

I don't have a better proposal. However I just noticed that the term "build profile" doesn't appear to be documented. My suggestion would be to fix that, or alternatively to use a different term if that one is better established and documented.

@jberryman
Copy link

It sounds like in the message "Build profile: -w ghc-8.6.5 -O1" the "-O1" will often be meaningless, one of many global defaults which might be overridden in sections of the cabal.projec(.local) or .cabal files.

I guess I'd suggest deleting the message unless someone can explain how it might be helpful info for users?

@tomjaguarpaw
Copy link
Member

I agree. It would be much more helpful to see the actual options that each package is being built with, but failing that seeing nothing at all is probably more helpful than seeing something that is misleading.

@jneira
Copy link
Member

jneira commented Sep 27, 2021

Well the ghc version is useful imo and the optimization level should reflect the top level config, taking in account the global config and several cabal.project.*
I guess it would be useful ask who added it via blame ☺️

@fgaz
Copy link
Member

fgaz commented Sep 27, 2021

#4605

@fgaz
Copy link
Member

fgaz commented Sep 27, 2021

There is a reason why that specific info is shown though. "build profiles" have separate caches, so switching between --disable-optimization and --enable-optimization should cause no recompilation. Same for -w. See #3343 for more info. We should check if this is mentioned in the docs.

@jberryman
Copy link

I just reminded myself that top-level things in cabal.project apply to all local packages, while a package * stanza will affect library dependencies as well. So I think I could be using optimization: 0 at the top level and would have gotten a sensible message (and also better caching behavior) IIUC

I'm kind of stumped on a good short-term solution. Maybe a message saying whether we are using an existing cached build profile directory would be just as useful?

Long term I wonder if what we want is:

  • build profile is the hash of all local package settings (after baking in top-level local package settings)
  • some good UX for clearing out older build profile artifacts

@gbaz
Copy link
Collaborator

gbaz commented Feb 18, 2022

I think a very easy "fix" would be to say instead of "Build profile" the slightly more verbose "Build profile (subject to package-level overrides"

@Mikolaj
Copy link
Member

Mikolaj commented Feb 18, 2022

That's a totally valid fix.

@ulysses4ever
Copy link
Collaborator

While this is probably an improvement, it's not ideal unless there's a diagnostic message later on that some of the mentioned parameters were, in fact, overridden. Also, GHC version is impossible to override, so it's not completely true either.

@Mikolaj Mikolaj removed the 3.8 label Jun 2, 2022
@Mikolaj Mikolaj added this to the 3.9 milestone Jun 2, 2022
@mouse07410
Copy link
Collaborator

mouse07410 commented Sep 5, 2022

Cabal-3.8.1.0.

Could you explain why Cabal reports -O1 even when ~/.cabal/config has ghc-options: -O2 and optimization: 2? Nothing in the local project settings explicitly configures optimization level, leaving it to the global default.

Leaving alone whether -O2 is (or is not) a good idea.

P.S. Thankfully, Cabal reports the GHC version correctly.

@fgaz
Copy link
Member

fgaz commented Sep 6, 2022

@mouse07410 what optimization level do you actually get when building the project? Is the message incorrect or is optimization from ~/.cabal/config not picked up at all? If it's the latter, could you open a new ticket about that?

@mouse07410
Copy link
Collaborator

@fgaz hard to say, because Cabal logging does not work either (see #8456). ;-)

But, based on the captured console output, -O2 does get passed to the GHC invocation. Presumably, from ghc-options: -O2, rather than from optimization: 2...?

It is unclear from the docs, whether I need just one of these (and if so - which one), or both: optimization: 2 and ghc-options: -O2. And it's unclear even if optimization: 2 is valid - but Cabal-3.8.1.0 did not complain about this value, so it must be acceptable...?

@ulysses4ever
Copy link
Collaborator

@mouse07410 did you read the doc? It suggests that optimization is meant to be more abstract setting. E.g. it can apply to (imaginary) Haskell compilers other than GHC, as well as, to GCC.
https://cabal.readthedocs.io/en/3.8/cabal-project.html#cfg-field-optimization

@mouse07410
Copy link
Collaborator

The doc says that it "builds with optimization" and passes -O2 to the C compiler.

Did it mean that GHC will also use -O2, or do I need to utilize ghc-options: -O2 in addition?

P.S. Docs IMHO do lack in the areas of clarity and comprehensiveness.

@ulysses4ever
Copy link
Collaborator

@mouse07410 you don't need ghc-options if you use optimization. For the docs: fully agree, and a contribution improving thereof would be very welcome!

@ulysses4ever
Copy link
Collaborator

ulysses4ever commented Sep 8, 2022

That is not to say that the Build profile business is good — it is not. My guess would be that it prints the message before it reads the config (where you have optimization: 2). Arguably, this could be a separate ticket, because it most certainly will require something more clever than simply changing the (still very confusing!) message.

@mouse07410
Copy link
Collaborator

My guess would be that it prints the message before it reads the config (where you have optimization: 2). . . it most certainly will require something more clever than simply changing the (still very confusing!) message

Admitting my lack of expertise here - why should it be any more complicated than printing the message after reading the config (when Cabal learns what GHC compiler is requested, and what options to pass to it)...?

@ulysses4ever
Copy link
Collaborator

@mouse07410 Very simply, because finding and changing a string is easier than moving the string, if you don’t know where to move exactly. Cabal’s code base is significant (after tests) it’s ~500 .hs files with ~100K SLOC (w/o spaces or comments).

And that’s assuming that my guess is right, which it may not be.

@ulysses4ever ulysses4ever added the re: user experience User experience (UX) issue label Nov 21, 2022
emdash-ie pushed a commit to emdash-ie/busboy-two that referenced this issue Jul 16, 2023
From haskell/cabal#6221, it seems like this is
the preferred way to set the optimisation level. I’m also not certain
whether this is taken into account when building with nix: it’s not
mentioned in the output of cabal2nix, so how does the builder know what
optimisation level to use?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests