Sunday, May 11, 2008

Speeding Up Compilation

Use a compiler cache.

When multiple people work on an active project together, the source code is bound to be updated fast and frequent. So developers would usually have to update their sources, resolve one or two conflicts occasionally, and RECOMPILE, i.e. make clean.

You also need to make clean when compiling for another hardware configuration with different compile time options and features. A typically embedded Linux project involves components like the Linux kernel, busybox, dns/dhcp/snmp/tr069/ppp/wireless/openssl, and so on. A typical compile time ranges from 5 to 20 minutes on a dual-Pentium 4 3.0GHz. Woe to those with lesser machines!

Our developers need to frequently recompile to test modifications, or simply when customizing features for customers. Most of their time is spent not excreting their creative juices but waiting for the compile to compete. When a significant part of the work is to clean compile from the same revision of the source, compile lag is certainly a creativity/productivity killer.

What about Makefile dependencies? Can't we use those? Unfortunately, they are unreliable. Being based on timestamps and not the actual content of the source files, having a previous (changed) version of a header file with an older timestamp does not trigger a recompile! Hence the frequent need to "make clean" to ensure the integrity of the compiled output.

Here are some stats from my own trial with ccache:

Original clean compile (nocache):
real 13m32.885s
user 11m31.488s
sys 1m28.270s

Clean compile (cached):
real 8m48.656s
user 7m33.143s
sys 1m13.740s

Close to 40% speedup is achieved. I believe there is more room for improvement, but for now, I am happy.