If you’re not already using MacPorts, you should be. I’ve got some introductory posts coming that will explain why and how. For now, suffice it to say that MacPorts opens the vast universe of open source to Mac users. It isn’t new, but I think it has matured and stabilized such that even non-developers can start tapping the vast universe of free Mac-compatible software. While you’re waiting, now would be a good time to download the latest Xcode 3.x release. Note that if you use your “unlimited” mobile data plan for this, I am not responsible for your $3,500 phone bill.
Today, I’ve got a simple but effective tip for dramatically reducing MacPorts build time. By default, no matter how many processors or cores you’ve got in your Mac, MacPorts compiles one file at a time. It’s time you put your extra core (or cores) to a better use than keeping those Flash ads running smoothly in your minimized Safari windows.
Easy
Assuming you’ve installed MacPorts in /opt/local, edit the file
/opt/local/etc/macports/macports.conf
and locate the parameter “buildmakejobs”. Change the 1 to a 2 and save, then kick off a build (e.g. “port install something“). On a dual-core uniprocessor Mac, there’s no point pushing it any higher because two build threads will max out your CPU. Limiting RAM-hungry and I/O demanding apps (Safari, Word, Mail, Spotlight searches) increases likelihood of success.
Expert
If you’ve got a Mac Pro or (non-production) Xserve with plenty of RAM, buildmakejobs can conceivably go as high as the number of cores, but you might hit a memory ceiling or a disk bottleneck before you get there. You may want to set a couple of cores aside for foreground apps.
Activity Monitor will show you how far you can push it. If it’s too much of a pig, just Control+C the port command, dial back the buildmakejobs setting, and reissue the port command to resume the interrupted build.
Unfortunately, the buildmakejobs setting doesn’t make fetches (source downloads) and compiles run simultaneously. Stupid-fast broadband is a good investment, but some repositories are just slow. Your fans will announce the transitions between fetches and builds.
A special note for notebooks
If you have a MacBook Pro, plug your machine in before building and for pity’s sake, don’t set it or the charging brick on your lap, a bed or a sofa cushion during a build. The hardware gets hot, and the fan will scream. Unless you’re a gamer, you may never have pushed your notebook as hard as a lengthy multi-threaded compile will do. In particular, your first few builds will be horrendous as MacPorts builds commonly-used libraries.
This trick is worth trying on any multi-core Mac, even a Mac mini or MacBook. My hunch is that you’ll want at least 4 GB of RAM, but you might get by with less if you shut down other apps.
If you’re up for an adventure, MacPorts is also compatible with distcc for distributing builds across multiple Macs. I haven’t used that facility in years, but this looks like a good cause. I’ll report back.