Skip to content

Compiling Stage0 HsInstances and DynFlags with -O slows down Hadrian build unnecessarily

Summary

Most Hadrian build flavours compile Stage0 compiler modules with -O, but HsInstances and DynFlags compile so slowly as to outweigh their increased performance elsewhere in the build. Exact times vary, but both take on the order of minutes to compile single threaded, with high wall clock times (still on the order of minutes for HsInstances).

Compiling them instead with -O0 for Stage0 significantly reduces build time and should not affect the resulting Stage1 binaries, though at least in the case of the quickest flavour, both DynFlags and HsInstances are compiled with -O0 for Stage1 anyway.

I discuss the results and the process of investigating these files a little more in my HSoC update blog.

Benchmarks

Modules with -O0 added at Stage0 Mean time Num Trials Speedup
No change 30m8s 4 1
HsInstances 27m42s 4 1.09
HsInstances, DynFlags 26m14s 8 1.15

Steps to reproduce

The times above were produced with these commands:

./hadrian/build.stack.sh clean
./hadrian/build.stack.sh -c -j -B --flavour=quickest --profile

To add -O0 to these modules only in Stage0, change the following in hadrian/src/Settings/Packages.hs (starting at line 50)

, builder (Ghc CompileHs) ? mconcat
  [ inputs ["//GHC.hs", "//GhcMake.hs"] ? arg "-fprof-auto"
  , input "//Parser.hs" ?
    pure ["-fno-ignore-interface-pragmas", "-fcmm-sink" ] ]

to

, builder (Ghc CompileHs) ? mconcat
  [ inputs ["//GHC.hs", "//GhcMake.hs"] ? arg "-fprof-auto"
  , input "//Parser.hs" ?
    pure ["-fno-ignore-interface-pragmas", "-fcmm-sink" ]
  , inputs ["//HsInstances.hs", "//DynFlags.hs"] ? stage0 ?
    pure ["-O0"] ]

Environment

  • GHC version used: Bootstrapping with GHC 8.6.5 using Stack
  • Operating System: Antergos Linux
  • System Architecture: x86-64
Edited by Jess
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information