Ccache: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(remove unneeded "mk_add_options" line. (the 'ac_add_options' line is all that's needed AFAIK))
(move content to devmo)
 
Line 1: Line 1:
[http://ccache.samba.org/ ccache] is a compiler cache for C and C++. It does what its function implies: caches the results of compilations. The net result: builds are faster!
ccache is a compiler cache that can make builds faster. For more, see [https://developer.mozilla.org/en/ccache developer.mozilla.org/en/ccache].
 
== Installing  ==
 
ccache is typically available in your operating system's package manager of choice.
 
On Mac:
 
$ brew install ccache
 
On Ubuntu:
 
$ apt-get install ccache
 
== Configuring ccache  ==
 
By default, ccache will put its cache in ''~/.ccache''. You can verify this by running:
 
$ ccache -s
 
That prints out the location of the current cache with some statistics.
 
You can modify the location of the cache via environment variables such as '''CCACHE_DIR'''. For more, see the man page (''man ccache'').
 
Like most anything that is I/O bound, ccache will benefit from having its cache on a fast I/O device, like an SSD. If you can, configure your cache to run off the fastest device you can. If you are using magnetic storage, put the cache on a separate spindle from the source tree you are building.
 
For example,
 
$ export CCACHE_DIR=/Volumes/Scratch/ccache
 
The default cache size is 1GB. A typical '''mozilla-central''' build of Firefox will fully saturate a cache of this size, evicting entries and thus lowering cache hit rate. You can modify the cache size as follows:
 
$ ccache --max-size 2GB
 
== Configuring Mozilla Builds  ==
 
To configure Mozilla builds to use ccache, you'll need to configure some make and configure options. In your ''.mozconfig'', add the following:
 
ac_add_options --with-ccache=/usr/bin/ccache
 
'''Be sure to specify the appropriate path to ccache on your system!'''
 
Now, run a build and verify the cache is being utilized:
 
$ ccache -s
cache directory                    /home/gps/.ccache
cache hit (direct)                    0
cache hit (preprocessed)              0
cache miss                            0
files in cache                        0
cache size                            0 Kbytes
max cache size                      2.0 Gbytes
$ make -f client.mk build
# in another shell, after the build has churned for a while:
$ ccache -s
cache directory                    /home/gps/.ccache
cache hit (direct)                    2
cache hit (preprocessed)              7
cache miss                          2044
called for link                      27
preprocessor error                    1
unsupported source language            1
autoconf compile/link                19
unsupported compiler option            4
files in cache                      6226
cache size                        659.0 Mbytes
max cache size                      2.0 Gbytes
 
== Sample Performance Impact  ==
 
The following lists sample impact of ccache on build times. The first build should be ran with ccache enabled, but an empty cache. The second build should be executed after a ''distclean''.
 
{| cellspacing="1" cellpadding="1" border="1" style="width: 835px; height: 251px;"
|-
! scope="col" | System Description
! scope="col" | Build Type
! scope="col" | First Build (Empty Cache)
! scope="col" | Second Build (Populated Cache)
! scope="col" | Change
|-
|
*Core i7-2600K
*64 bit Linux VM inside Windows 7
*2.5GB RAM
*Source and cache on same spindle
 
|
*-O2
*-j8
*browser application
*--enable-tests
*mozilla-central on 2011-08-11
 
|
*17:30 wall
*37:04 user
*4:28 sys
 
|
*7:12 wall
*2:51 user
*1:04 sys
 
|
*-10:28 wall (59% faster)
*-34:13 user (92% faster!)
*-3:24 sys (76% faster)
 
|}
 
== Related Links  ==
 
*http://blog.lassey.us/2010/07/19/ccache-configure-option-for-mozilla/
*http://forums.mozillazine.org/viewtopic.php?f=42&t=405015
*http://weblogs.mozillazine.org/darin/archives/005504.html

Latest revision as of 00:05, 12 August 2011

ccache is a compiler cache that can make builds faster. For more, see developer.mozilla.org/en/ccache.