ccache
ccache is a compiler cache. It acts as a caching pre-processor to
C/C++ compilers, using the -E compiler switch and a hash to detect
when a compilation can be satisfied from cache. This often results in
a 5 to 10 times speedup in common compilations.
The idea came from Erik Thiele wrote the original compilercache program
as a bourne shell script. ccache is a re-implementation of Erik's idea
in C with more features and better performance.
Latest release
The latest release is ccache 2.4.
- Added CCACHE_READONLY option
- Added CCACHE_TEMPDIR option
- fixed handling of hard-linked compilers on AIX
- added O_BINARY support, to try and support win32 compiles
- show cache directory in stats output
- fixed handling of HOME environment variable
See the manual page for details
on the new options.
You can get this release from the download directory
NOTE! This release changes the hash input slighly, so you will
probably find that you will not get any hits against your existing
cache when you upgrade.
Why bother?
Why bother with a compiler cache? If you ever run "make clean; make"
then you can probably benefit from ccache. It is very common for
developers to do a clean build of a project for a whole host of
reasons, and this throws away all the information from your previous
compiles.
By using ccache you can get exactly the same effect as "make clean;
make" but much faster. It also helps a lot when doing RPM builds,
as RPM can make doing incremental builds tricky.
I put the effort into writing ccache for 2 reasons. The first is the
Samba build farm
(http://build.samba.org/)
which constantly does clean builds of Samba on about 30 machines after each
CVS commit. On some of those machines the build took over an hour. By
using ccache we get the same effect as clean builds but about 6 times
faster.
The second reason is the autobuild system I used to run for
Quantum. That system builds our whole Linux based OS from scratch
after every CVS commit to catch compilation problems quickly. Using
ccache those builds are much faster.
Is it safe?
Yes. The most important aspect of a compiler cache is to always
produce exactly the same output that the real compiler would
produce. The includes providing exactly the same object files and
exactly the same compiler warnings that would be produced if you use
the real compiler. The only way you should be able to tell that you
are using ccache is the speed.
I have coded ccache very carefully to try to provide these guarantees.
Features
- keeps statistics on hits/misses
- automatic cache size management
- can cache compiles that generate warnings
- easy installation
- very low overhead
- uses hard links where possible to avoid copies
Documentation
See the manual page
Performance
Here are some results for compiling Samba on my Linux laptop. I have
also included the results of using Erik's compilercache program
(version 1.0.10) for comparison.
| ccache | compilercache |
normal | 13m 4s | 13m 4s |
uncached | 13m 15s | 15m 41s |
cached | 2m 45s | 4m 26s |
How to use it
You can use ccache in two ways. The first is just to prefix your
compile commands with "ccache". For example, you could change the
"CC=gcc" line in your Makefile to be "CC=ccache gcc".
Alternatively, you can create symbolic links from your compilers name
to ccache. This allows you to use ccache without any changes to your
build system.
Download
You can download the latest release from the download directory.
For the bleeding edge, you can fetch ccache via CVS or
rsync. To fetch via cvs use the following command:
cvs -d :pserver:cvs@pserver.samba.org:/cvsroot co ccache
To fetch via rsync use this command:
rsync -Pavz samba.org::ftp/unpacked/ccache .
Related projects
Here are some related programs you may find interesting
- distcc - a distributed compilation system
- cachecc1 - a gcc specific cache
- gocache - a cross platform compiler cache
Mailing list
A mailing
list is available for discussion of ccache.
Andrew Tridgell
bugs@ccache.samba.org