Compiling at the speed of light

By Oli on Tuesday, 25th March 2008. More information. Comments.

By default the make command won't use more than one process to compile things. With a tiny bit of tweaking you can slice off precious minutes and save yourself a noticeable amount of time.

While most Linux users can get by perfectly well without compiling anything, I don't count myself amongst their ranks. If you play games through Wine or like to test the very latest Firefox has to offer, you need to download the source and compile things up for your system. The problem: this takes a damned long time.

Multi-core processors have been with us for some time now. I've had my X2 4800+ for almost 2 years now and I've been loving it. Most of the applications that are CPU intensive know how to take advantage of them and that's all great. Unfortunately make isn't one of them.

But make has a --jobs (-j) option, allowing you to fracture the compilation into several processes. It is recommended that you use n+1 jobs, where n is the number of cores your processor contains. I have 2 cores, so I run this:

make -j3

The performance gain is immense. Here are the times for one and two core (three "jobs") building, respectively:

1core: 25m59s. 2cores: 14min47s

real shows the actual time taken. user shows the amount of CPU time used. sys shows the time taken on related kernel processing.

So specifying the cores can save you about 43% of the total build time for Wine. I've tested this with other applications and the savings where all around 40%. If you have a quad-core, I'd love to see how much faster you can build it using -j5.

I've also looked at compiling from RAM. I created a 1gig RAMdisk using tmpfs, copied the source there and compiled with the -j3 option but this only gave an extra few seconds performance improvement. RAMdisks are massively faster for heavy I/O operations than mechanical disks, so the poor improvement shows that compilation (at least in Wine's case) bottlenecks on the CPU more than anywhere else.

Grav

Written by Oli on Tuesday, 25 March 2008. Tagged with linux. Read 3094 times. If you liked it, please give it a digg.

#1 /* 2 years, 10 months ago */
I'm not sure but unless you have way too much RAM already, preloading the source into the RAM will end up restricing the amount of RAM available for compilation, I'm no expert but I've observed my system getting pretty RAM starved on large compiles (like Firefox, Wine, or OpenOffice).

But seriously, one of the reasons I fell in love with linux is the RAM drive. I usually have my download directory in Firefox set to dump everything into /dev/shm/ (except for the biggest files of course).

I like your articles, they have a professional lab report style to them. I haven't read enough to know your full skill set but if your the kind of masochist that likes compiling software then you'd be right at home with Gentoo. Either that or you could run your own Ubuntu Apt repository.

Don't just sit there like a lemon! Reply!

Got something to say? Now's the time to share it with the author and everybody else that reads this posting! Lemons need not apply.

edtBOX - xHTML: yes - bbcode:no
Home | Advertise | About | Contact | Legal © Oli Warner 2001—2007 Proud 9rules member