Skip to content
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

More conservative SCC tagging for Haskell libraries #45677

Merged
merged 1 commit into from Sep 3, 2018

Conversation

alexbiehl
Copy link
Contributor

all-functions corresponds to -fprof-auto which places an SCC on every binding. It is well known that SCCs hinder GHC from doing its optimization magic and really slows down profiled code to a point where the profiling reports are completely skewed towards things that were completely optimized away in production settings. Concretely this shows up with things like lenses which do not carry runtime overhead when properly simplified.

exported-functions corresponds to GHCs -fprof-auto-exported which doesn't put SCCs on INLINEd code and in turn doesn't influence simplification of this basic but important stuff.

This is even more important as per GHC-8.4 SCCs are also put into unfoldings which make you pay for it at each call site.

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

`all-functions` corresponds to `-fprof-auto` which places an SCC on every binding. It is well known that SCCs hinder GHC from doing its optimization magic and really slows down profiled code to a point where the profiling reports are completely skewed towards things that were completely optimized away in production settings. Concretely this shows up with things like lenses which do not carry runtime overhead when properly simplified.

`exported-functions` corresponds to GHCs `-fprof-auto-exported` which doesn't put SCCs on `INLINE`d code and in turn doesn't influence simplification of this basic but important stuff.
@shlevy
Copy link
Member

shlevy commented Aug 27, 2018

@ryantm @peti @basvandijk Would like confirmation from at least one of you before going ahead, but this seems to be the right default to me.

@ryantm
Copy link
Member

ryantm commented Aug 27, 2018

@alexbiehl You can change the merge base of your PR by clicking the edit button at the top of the PR near the title.

You can also force-push an update to the branch on GitHub to change the PR.

@alexbiehl
Copy link
Contributor Author

You can change the merge base of your PR by clicking the edit button at the top of the PR near the title.

Interesting, that must be new stuff!

Copy link
Member

@peti peti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexbiehl, are there any use-cases where people would actually want profiling for all-functions rather than exported-functions? Or is the latter flag totally and unambiguously better than the former? I wonder because the authors of ghc and Cabal chose all-functions profiling as their default, and I have to assume there are reasons for that choice?

Copy link
Member

@basvandijk basvandijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the right default.

When the package you're working on is slow you probably want to profile it by entering a nix-shell that brings all the dependencies into scope. Then you probably want to see a detailed profiling report of all the functions in your package so you can spot where time is being spent. So you'll probably use all-functions. However you probably don't care about the inner workings of your dependencies. You just want to see how much time is being spent in the functions you call from your dependencies. So I think for dependencies the proposed exported-functions makes the most sense.

@alexbiehl
Copy link
Contributor Author

However you probably don't care about the inner workings of your dependencies. You just want to see how much time is being spent in the functions you call from your dependencies.

Exactly!

@basvandijk
Copy link
Member

basvandijk commented Aug 28, 2018

@peti

are there any use-cases where people would actually want profiling for all-functions rather than exported-functions?

When you're working on a collection of packages people might want to profile with all-functions to investigate how the packages work together. However in that case people are likely in full control of those packages and will be able to override them with profilingDetail="all-functions".

I wonder because the authors of ghc and Cabal chose all-functions profiling as their default, and I have to assume there are reasons for that choice?

I think the reason is what I explained above. It's the proper default for profiling the package you're working on. Probably not for dependencies.

We could ask the GHC devs for advise if we're unsure.

@peti peti force-pushed the haskell-updates branch 3 times, most recently from b2a773d to 2b2430d Compare September 3, 2018 09:58
@shlevy shlevy merged commit 3c70c4c into NixOS:haskell-updates Sep 3, 2018
@alexbiehl alexbiehl deleted the haskell-updates branch September 3, 2018 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants