There’s a very useful tool for gcc and similar compilers called ccache which many people may not be aware is installed on their system. It is a compiler cache. Supported languages include C, C++, Objective-C and Objective-C++. The idea behind ccache is to speed up code recompilation by caching the result of previous compilations and detecting when the same compilation is being done again. While it may take a few seconds longer to compile a program the first time you use ccache, subsequent compiles will typically be much faster.
Here is what my ccache cache statistics look like after a few months of compiling various applications:
$ ccache -s cache directory /home/fpm/.ccache cache hit (direct) 5649 cache hit (preprocessed) 383 cache miss 27404 called for link 5017 called for preprocessing 1805 multiple source files 7 compile failed 465 preprocessor error 164 bad compiler arguments 407 unsupported source language 31 autoconf compile/link 3229 unsupported compiler option 3 no input file 1498 files in cache 26626 cache size 924.6 Mbytes max cache size 1.0 Gbytes $ cd ~/.ccache $ ls -al total 80 drwxrwxr-x 19 fpm fpm 4096 Jun 30 2012 . drwxr-xr-x 49 fpm fpm 4096 Mar 14 03:01 .. drwxrwxr-x 18 fpm fpm 4096 Jan 30 21:09 0 drwxrwxr-x 18 fpm fpm 4096 Jan 30 21:09 1 drwxrwxr-x 18 fpm fpm 4096 Jan 30 21:09 2 drwxrwxr-x 18 fpm fpm 4096 Jan 30 21:09 3 drwxrwxr-x 18 fpm fpm 4096 Jan 30 21:09 4 drwxrwxr-x 18 fpm fpm 4096 Jan 30 21:09 5 drwxrwxr-x 18 fpm fpm 4096 Jan 30 21:09 6 drwxrwxr-x 18 fpm fpm 4096 Mar 4 10:58 7 drwxrwxr-x 18 fpm fpm 4096 Mar 4 10:58 8 drwxrwxr-x 18 fpm fpm 4096 Mar 4 10:58 9 drwxrwxr-x 18 fpm fpm 4096 Jan 30 21:09 a drwxrwxr-x 18 fpm fpm 4096 Jan 30 21:09 b drwxrwxr-x 18 fpm fpm 4096 Jan 30 21:09 c -rw-rw-r-- 1 fpm fpm 190 Jun 18 2012 CACHEDIR.TAG drwxrwxr-x 18 fpm fpm 4096 Mar 4 10:58 d drwxrwxr-x 18 fpm fpm 4096 Jan 30 21:09 e drwxrwxr-x 18 fpm fpm 4096 Mar 4 10:58 f drwxrwxr-x 2 fpm fpm 4096 Jan 30 21:09 tmp $ $ cd f/f $ ls -l total 2148 -rw-rw-r-- 1 fpm fpm 6435 Nov 2 18:21 0a632930c6b3a5e0b23bd1b4ebca1e-82602.manifest -rw-rw-r-- 1 fpm fpm 33830 Nov 2 15:29 0b3cef8ce8e69c25b4d1f26c401896-36044.manifest -rw-rw-r-- 1 fpm fpm 4270 Nov 2 16:06 0ce14408ae925b994b8d9c54b28f75-50633.d -rw-rw-r-- 1 fpm fpm 945 Nov 2 16:06 0ce14408ae925b994b8d9c54b28f75-50633.o -rw-rw-r-- 1 fpm fpm 10372 Nov 2 18:20 1172b26ad90ba289c5715ea597237e-386743.d -rw-rw-r-- 1 fpm fpm 16368 Nov 2 18:20 1172b26ad90ba289c5715ea597237e-386743.o -rw-rw-r-- 1 fpm fpm 27240 Jan 30 21:09 1270a4dd79671332c60f531bf56360-111704.o -rw-rw-r-- 1 fpm fpm 61706 Nov 2 15:03 13a8ecc043d194fee1f721a9702dff-2694676.d -rw-rw-r-- 1 fpm fpm 15520 Nov 2 15:03 13a8ecc043d194fee1f721a9702dff-2694676.o -rw-rw-r-- 1 fpm fpm 40310 Nov 2 14:29 1f37e26f195d6a0a69d4e0428f67b5-1100836.d -rw-rw-r-- 1 fpm fpm 104424 Nov 2 14:29 1f37e26f195d6a0a69d4e0428f67b5-1100836.o -rw-rw-r-- 1 fpm fpm 13720 Jan 30 21:09 28a55ea10e58a91ac40f7b4ab97822-82191.o -rw-rw-r-- 1 fpm fpm 1240 Nov 2 17:27 34197bcdb4d8671f13ed9b9cab0658-256.o -rw-rw-r-- 1 fpm fpm 54539 Nov 2 15:42 3ba24e8b3ea4aee5e0d1311a024c0d-2422333.d -rw-rw-r-- 1 fpm fpm 24680 Nov 2 15:42 3ba24e8b3ea4aee5e0d1311a024c0d-2422333.o ...
You can clear out the ccache cache as follows:
$ ccache -C Cleared cache [fpm@ultra f]$ ccache -s cache directory /home/fpm/.ccache cache hit (direct) 5649 cache hit (preprocessed) 383 cache miss 27404 called for link 5017 called for preprocessing 1805 multiple source files 7 compile failed 465 preprocessor error 164 bad compiler arguments 407 unsupported source language 31 autoconf compile/link 3229 unsupported compiler option 3 no input file 1498 files in cache 0 cache size 0 Kbytes max cache size 1.0 Gbytes $
You can also reduce the maximum size of the ccache cache:
$ ccache -M 500M Set cache size limit to 500.0 Mbytes $
Fedora by default seems to allocate 1Gb of ccache cache space.