Mastodon
sungate.co.uk

sungate.co.uk

Ramblings about stuff

C compiler geekiness

Recently discovered two rather handy little utilities for making C compilations faster … distcc and ccache.

You can use distcc to distribute a compilation to a number of different systems – for example, if there are a number of fast machines on your local network, you can use all of them to reduce the compilation times considerably. If you have N machines, your maximum theoretical limit is to reduce the compile time by a factor of N, although there is some network overhead etc. This seems to work rather well.

On the other hand, ccache caches the results of previous compilation runs so that when you re-compile or re-build the results can be pulled from the cache rather than requiring a (possibly lengthy) full re-compilation. ccache works by keeping a hash of the compiler options and the preprocessed object etc., so that if it sees exactly the same again, no re-compilations is necessary. This means that you can still do a ‘make clean’ and get the benefit of ccache.

You can also use ccache and distcc together, which makes a real difference.

An example using ccache: I have a custom-built copy of Psi, the jabber instant-messaging client – I customize it because the colour schemes are not configurable through the user interface, but hardcoded into the source. And the defaults really hurt my eyes … So, I need to recompile the source code after making a number of small changes, editing the hex codes for the colours – on my machine this takes about 10 minutes, which is a long time just to see what the new colours look like in the running program. However, by using ccache to cache most of the (unchanged) modules in the compilation job, build time is reduced to less than a minute for the second and subsequent builds. Which Is Nice. 🙂

At work, I’ve setup distcc and ccache to build kernels for all our Debian servers – using three build hosts, it can build three Debian kernel packages in less than five minutes …