commit:     b3b64a95b9653963a2868278fd0130858a9eb9f0
Author:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
AuthorDate: Fri Sep  2 09:26:43 2016 +0000
Commit:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
CommitDate: Fri Sep  2 09:29:51 2016 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b3b64a95

haskell-cabal.eclass: unleash full parallelism of parallel ghc

I've explored scalability of 'ghc --make -j' a bit in
    https://ghc.haskell.org/trac/ghc/ticket/9221

Some takeaways:
- never specify -j<N> with N > CPU. garbage collector threads
  waste kernel time running sched_yield()
- GHC allocates A Lot: large nursery decreases GC interruptions.
  We fix it with '-A256M'
- for large nursery enabling work-stealing makes GC finish faster
  on each collection cycle.
  We fix it with -qb0

While at it move HCFLAGS setup after parallel defaults.
That allows user to override defaults with own HCFLAGS.

Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>

 eclass/haskell-cabal.eclass | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/eclass/haskell-cabal.eclass b/eclass/haskell-cabal.eclass
index c1a1330..94ef7f3 100644
--- a/eclass/haskell-cabal.eclass
+++ b/eclass/haskell-cabal.eclass
@@ -372,24 +372,20 @@ cabal-configure() {
                cabalconf+=($(cabal-constraint "ghc"))
        fi
 
+       # parallel on all available cores
+       if ghc-supports-parallel-make; then
+               # It should have been just -j$(makeopts_jobs)
+               # but GHC does not yet have nice defaults:
+               #    https://ghc.haskell.org/trac/ghc/ticket/9221#comment:57
+               cabalconf+=(--ghc-options="-j$(makeopts_jobs) +RTS -A256M -qb0 
-RTS")
+       fi
+
        local option
        for option in ${HCFLAGS}
        do
                cabalconf+=(--ghc-option="$option")
        done
 
-       # parallel on all available cores
-       if ghc-supports-parallel-make; then
-               local max_jobs=$(makeopts_jobs)
-
-               # limit to very small value, as parallelism
-               # helps slightly, but makes things severely worse
-               # when amount of threads is Very Large.
-               [[ ${max_jobs} -gt 4 ]] && max_jobs=4
-
-               cabalconf+=(--ghc-option=-j"$max_jobs")
-       fi
-
        # Building GHCi libs on ppc64 causes "TOC overflow".
        if use ppc64; then
                cabalconf+=(--disable-library-for-ghci)

Reply via email to