Why does the Macports package of GHC take so long to compile?


Question or issue on macOS:

And why? There is a bootstrap process and compiling the real compiler process, but which part consumes the most time?

How to solve this problem?

Solution no. 1:

From the Gentoo perspective:

In Gentoo, everything is compiled. What we do for GHC is that us devs (including unofficial devs like myself) compile a new version of GHC from an older one to create a binary bootstrapping version, and then package that up and let users use that one to compile a new version.

From memory, compiling the binary can take more than twice as long (takes about 45 minutes to use the binary to compile a new version on my laptop). There are some differences (the documentation is built and shipped with the binary rather than each user building it themselves) but none that I can see to account for such a large time difference. The actual ebuild used to build both the binary and for end users can be found here (enabling the ghcbootstrap flag means it builds a binary, enabling the binary flag means that users install and use the prebuilt binary rather than building GHC themselves): http://code.haskell.org/gentoo/gentoo-haskell/dev-lang/ghc/ghc-6.12.3.ebuild

As such, my guess is that it’s the initial bootstrapping process that takes so long if Macports is indeed building an initial bootstrapping binary (especially if it’s doing so from the last C-only release and bootstrapping its way up to the version you actually want to install).

Solution no. 2:

Building GHC is notorious for taking forever. I’ve heard horror stories about it taking in excess of 8 hours for a from-source build. From what I understand, it is mainly due to the fact that the default build of GHC attempts to do massive amounts of optimization in order to speed its own runtime performance. Even with a partially prebuilt system (which is what I believe macports provides) this process still can take a while because of all the linking.

EDIT: See the following

Solution no. 3:

It can take a while. When I used to compile it on my iBook G4, it took as long as 7 hours. Even on a MacBook Pro with plenty of RAM and a fast processor, it can take 2-3 hours.

Solution no. 4:

Some build processes take quite a while, and the amount of time depends strongly on the speed of your CPU and how much processor time can be devoted to the build.

If you’re worried that it may be hanging in at a certain point, run install with the -v flag to get more descriptive output relating to the build process. The command would thus be something like:

sudo port -v install [portfile]

Hope this helps!