Ccache

ccache is a compiler cache which speeds up the recompilation of (almost) same packages.

However, Gentoo users often overestimate it, and fail to measure its effect correctly. That aspect is explained, too.

Introduction
Ccache uses the GCC -E switch and a hash to detect when a compilation can be satisfied from cache. The effect is that packages frequently recompile faster on the condition that GCCs output stays the same.

The first time that you emerge a package after setting up ccache, there will be a very slight increase in its compilation time, but thereafter when the compilation is cached you will notice significant reductions in completion times.

Caveats

 * Don't report bugs to gentoo if you've emerged using ccache. Turn it off, and try again. There're many reports of compilation failure due to corrupt cache.
 * Generally, ccache will only help performance if you need to recompile the (almost) same packages many times. For instance ccache does not speed up compile time if you change your CFLAGS or often even USE flags.
 * Until you're sure of the effect, it is recommended to check the statistics explained below.

For more, see and.

Installation
Begin with emerging :

Portage
After you've emerged ccache, you'll need to add ccache to the FEATURE line in for emerge to use ccache:

Also note the CCACHE_DIR and CCACHE_SIZE variables. They are optional, and are set to the defaults in the example above. See for more information.

Userspace
There are two ways to configure ccache to work for the regular user. The first is to export the CC variable to point to the ccache symlink when you run the autotools configure script:

Alternatively, set the PATH variable to begin with ccache's symlink directory in your profile :

ccache-config
The other way to enable ccache system-wide by default is to have install ccaches symlinks. To do this you'll first need to know your systems CHOST:

This should output something similar to: CHOST="i686-pc-linux-gnu" Now run with the --install-links argument followed by your CHOST. So, following our example above:

Statistics
To view ccache statistics, run with the -s switch. This will report the users ccache usage, for example:

cache directory                    /home/gentoouser/.ccache cache hit                          2500 cache miss                         1311 called for link                      10 compile failed                        3 couldn't find the compiler            1 autoconf compile/link                98 no input file                        87 files in cache                     2622 cache size                        114.0 Mbytes max cache size                    976.6 Mbytes If you want to see the statistics for another user, for example if you want to see the statistics for your regular user when you're superuser, you'll need to prefix with the CCACHE_DIR variable, so:

Portage
To see the Portage ccache statistics, export the CCACHE_DIR variable you set in, if you didn't set this, the default is :

Genkernel
Genkernel doesn't use ccache by default, even when you've enabled it for root. You can easily fix this by appending the --kernel-cc option to your genkernel call:

You can configure the KERNEL_CC setting to always use ccache with genkernel by editing as follows:

Version bumps

 * openssl minimal upgrade: In the minimal upgrade of openssl 1.0.0c -> 1.0.0d, 177/703 hits were there, and it took longer time to compile the latter. (The former was compiled with an empty cache.)
 * minimal stable bump of openssh: Update of openssh 5.6_p1-r2 -> 5.8_p1 was a minimal bump in amd64 stable, and only 16/307 hits were seen.

Kernel compilation
In compiling the kernel, ccache doesn't help at all for most cases. If you want to bisect the kernel, then it will take effect only when the number of remaining patches fall below about 200.

Links

 * The ccache Homepage
 * The offical Gentoo ccache documentation