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

Add a performance measuring top-level user guide page #10539

Merged
merged 39 commits into from
Nov 25, 2024

Conversation

malteneuss
Copy link
Collaborator

Another step of the user guide improvement initiative #9214:

Add a simple profiling user-guide page based on https://discourse.haskell.org/t/ghc-profiling-a-cabal-project-with-an-interactive-application/10465/2?u=malteneuss, which the author allowed us to use.

Feel free to modify yourself if that is faster.

  • Patches conform to the coding conventions.
  • Is this a PR that fixes CI? If so, it will need to be backported to older cabal release branches (ask maintainers for directions).

@Kleidukos
Copy link
Member

Thanks a bunch for starting this. Several things:

  • I would recommend that you make use of the ghc-prof-options key, which is used like this:
ghc-prof-options: -fprof-auto -fno-prof-count-entries -fprof-auto-calls

doc/how-to-analyze-haskell-code-performance.rst Outdated Show resolved Hide resolved
doc/how-to-analyze-haskell-code-performance.rst Outdated Show resolved Hide resolved
doc/how-to-analyze-haskell-code-performance.rst Outdated Show resolved Hide resolved
doc/how-to-analyze-haskell-code-performance.rst Outdated Show resolved Hide resolved
doc/how-to-analyze-haskell-code-performance.rst Outdated Show resolved Hide resolved
doc/how-to-analyze-haskell-code-performance.rst Outdated Show resolved Hide resolved
doc/how-to-analyze-haskell-code-performance.rst Outdated Show resolved Hide resolved
@malteneuss
Copy link
Collaborator Author

malteneuss commented Nov 9, 2024

Thanks for the quick review @Kleidukos and @geekosaur. I've added all your review remarks. Yes, the json output can be loaded into speedscope directly. This https://github.com/mpickering/hs-speedscope only deals with eventlog files, which irrc is another profiling report format to analyze memory consumption (some topic for a future section in this guide), although it also measures cpu performance.

@tchoutri
Copy link
Collaborator

tchoutri commented Nov 9, 2024

@malteneuss Much better, only two more changes to make and we should be good to go! :)

Copy link
Collaborator

@jasagredo jasagredo left a comment

Choose a reason for hiding this comment

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

My understanding is that eventlog profiling is far superior than just -pj, and it is (for recent GHCs) just a matter of passing -l -p instead (or if a smaller eventlog is wanted -l-agu -p). I have personally never used the json profiling report.

doc/how-to-analyze-haskell-code-performance.rst Outdated Show resolved Hide resolved
@malteneuss
Copy link
Collaborator Author

malteneuss commented Nov 9, 2024

@jasagredo Do you have a link to a post or blog that discusses the differences? I have never used it. Would you like to add a second section showing how to use it in another MR? I think we should add another section for profiling memory, where eventlog should be discussed after all.

@malteneuss malteneuss added the merge me Tell Mergify Bot to merge label Nov 9, 2024
@mergify mergify bot added the ready and waiting Mergify is waiting out the cooldown period label Nov 9, 2024
@ulysses4ever
Copy link
Collaborator

Thank you for taking this on! It's amazing to see efforts in expanding the guide section! I have certain critique below but, please, realize that documentation is a matter where reasonable people can disagree. I can survive the current version, especially given that you already got the mandatory two approvals.

IMO the text uses a cabal workflow that is suboptimal. In particular:

  1. It advocates for explicit cabal build, while you never need an explicit build in simple scenarios (including profiling). You should use cabal run where possible and rely on cabal to manage (re)compilation.

  2. (In part, because of (1)) it has to use $(cabal list-bin my-app) in an earlier, supposedly lighter subsection. This is long (i.e. annoying), quite platform-dependent (i.e. it assumes bash; I normally don't use bash even under Linux, for instance), and perfectly avoidable (see below).

  3. In an earlier, supposedly lighter subsection, it mentions adding profiling-related GHC options in a cabal file. Even though it's done as a note, this idea comes too early (advanced options should come later) and also gives a bad advice (you shouldn'g use cabal file for it -- a project file is the right place).

I propose solving most (all) of these with the following reformatting.

  • Start with cabal configure and explain that it creates cabal.project.local with local configuration.
  • Now, simply cabal run works.
  • Now you can mention the advanced GHC options. You are able to put them in the local project file at this point. Optionally, you could have a little subsection at the very end instead of here. You could also say two words why these options are good in there.
  • Now comes the section Profiling your dependencies too.

Copy link
Collaborator

@ulysses4ever ulysses4ever left a comment

Choose a reason for hiding this comment

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

I temporarily block it to make sure you have enough time to respond.

doc/how-to-analyze-haskell-code-performance.rst Outdated Show resolved Hide resolved
@jasagredo
Copy link
Collaborator

jasagredo commented Nov 10, 2024

Re-reading the document again I am unsure this describes Cabal's job on profiling. I think the section should be more about what options does cabal need to enable profiling than how to produce a profiling report, therefore I think the title is misleading and we are stepping into GHC's User Guide territory.

My suggestion would be to leave most of the description and RTS options to the GHC User guide and describe only the following in the text:

  • A brief explanation on why building for profiling is different (one has to link to the profiling RTS and insert cost-centres)
  • How to enable profiling (either via flag or via cabal.project)
  • The different options to enable profiling (library-vanilla for example)
  • The different customizations cabal provides (like profiling-detail which uses different names than GHC) and how they map to GHC options
  • How to pass other GHC profiling options.
  • How to enable profiling for specific dependencies or for all dependencies.
  • The usual caveats (for example I build with --enable-profiling, then using only run will re-build without profiling because the flags used during building are not persistent)

This way the choice of p vs pj, or what files are produced or where to load them is deferred to the User Guide, as it is GHC-specific business.

This way we don't mix "How to profile" and "How to configure for profiling". The latter is Cabal's job, but the former is GHC or general Haskell information which should not live in Cabal's docs I think. It will always be too specific or too general what you can say there and it might depend on GHC versions and so on.

@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Nov 11, 2024
@Mikolaj
Copy link
Member

Mikolaj commented Nov 12, 2024

OTOH, for some users a full example session of profiling would be immensely valuable and precisely what they are looking for, in despair reaching even for the cabal documentation. So maybe at least link to the original discourse post, saying it contains practical examples, including how to tweak GHC to profile best, which is out of scope of the cabal guide?

@malteneuss
Copy link
Collaborator Author

I fixed the typos. Further changes, especially to other pages, should go to separate MRs.

@malteneuss malteneuss requested a review from jasagredo November 21, 2024 21:16
@malteneuss malteneuss added the squash+merge me Tell Mergify Bot to squash-merge label Nov 21, 2024
@mergify mergify bot added the ready and waiting Mergify is waiting out the cooldown period label Nov 22, 2024
@AndreasPK
Copy link
Collaborator

I've left some comments for accuracy/brevity. But this is good work!

@ulysses4ever
Copy link
Collaborator

@AndreasPK I don't see your comments.

@geekosaur
Copy link
Collaborator

Nor do I. Did you actually submit them, or leave them pending?

@AndreasPK
Copy link
Collaborator

Seems they were pending :)

@ulysses4ever ulysses4ever removed squash+merge me Tell Mergify Bot to squash-merge ready and waiting Mergify is waiting out the cooldown period labels Nov 23, 2024
@ulysses4ever
Copy link
Collaborator

Thanks!

I remove the merge label until the comments are resolved.

@geekosaur
Copy link
Collaborator

That's not really necessary; since they're conversations on specific lines, they count as unresolved and GitHub won't allow merging (see the big red "Unresolved conversations" box). It's comments like this one that don't count because they're not considered review comments.

@ulysses4ever
Copy link
Collaborator

@geekosaur i thought it’s only respected by GitHub, not Mergify. But good to know, thanks.

@geekosaur
Copy link
Collaborator

geekosaur commented Nov 23, 2024

It's part of the branch protection rules, which Mergify copies into its own rules. See the first checkbox in the "merge+no rebase" ruleset in the Mergify summary check. (ETA: whoops, wrong PR, it's the "squash+merge me" ruleset in this case.)

@malteneuss malteneuss requested a review from AndreasPK November 23, 2024 20:53
@AndreasPK
Copy link
Collaborator

Seems all my points have been addressed. It seems I can't resolve the conversation as it's outdated perhaps? Anyway from my POV this looks good now :)

@malteneuss malteneuss added the squash+merge me Tell Mergify Bot to squash-merge label Nov 23, 2024
@mergify mergify bot added ready and waiting Mergify is waiting out the cooldown period merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days labels Nov 23, 2024
@mergify mergify bot merged commit 02da008 into haskell:master Nov 25, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days ready and waiting Mergify is waiting out the cooldown period squash+merge me Tell Mergify Bot to squash-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants