Revision 30021 of ccache

  • Revision slug: ccache
  • Revision title: ccache
  • Revision id: 30021
  • Created:
  • Creator: gps
  • Is current revision? No
  • Comment formatting; one or more formatting changes

Revision Content

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!

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.

System Description

Build Type

First Build (Empty Cache)

Second Build (Populated Cache)

Change

  • Core i7-2600K

  • 64 bit Linux VM inside Windows 7

  • 2.5GB RAM

  • Source and cache on same spindle

  • browser application

  • -j8

  • --enable-tests

  • -O2

  • 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

Revision Source

<p><a class=" external" href="http://ccache.samba.org/" title="http://ccache.samba.org/">ccache</a> 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!</p>
<h2>Installing</h2>
<p>ccache is typically available in your operating system's package manager of choice.</p>
<p>On Mac:</p>
<pre><code>$ brew install ccache </code></pre>
<p>On Ubuntu:</p>
<pre><code>$ apt-get install ccache</code></pre>
<h2>Configuring ccache</h2>
<p>By default, ccache will put its cache in <code>~/.ccache</code>. You can verify this by running:</p>
<pre><code> $ ccache -s</code></pre>
<p>That prints out the location of the current cache with some statistics.</p>
<p>You can modify the location of the cache via environment variables such as <strong>CCACHE_DIR</strong>. For more, see the man page (<code>$ man ccache</code>).</p>
<p>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.</p>
<p>For example,</p>
<pre><code>$ export CCACHE_DIR=/Volumes/Scratch/ccache </code></pre>
<p>The default cache size is 1GB. A typical <em>mozilla-central</em> 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:</p>
<pre><code> $ ccache --max-size 2GB</code></pre>
<h2>Configuring Mozilla Builds</h2>
<p>To configure Mozilla builds to use ccache, you'll need to configure some make and configure options. In your <em>.mozconfig</em>, add the following:</p>
<pre><code> ac_add_options --with-ccache=/usr/bin/ccache</code></pre>
<p><strong>Be sure to specify the appropriate path to ccache on your system!</strong></p>
<p>Now, run a build and verify the cache is being utilized:</p>
<pre><code>$ ccache -s</code>

<code>cache directory /home/gps/.ccache</code>
<code>cache hit (direct)                     0</code>
<code>cache hit (preprocessed)               0</code>
<code>cache miss                             0</code>
<code>files in cache                         0</code>
<code>cache size                             0 Kbytes</code>
<code>max cache size                       2.0 Gbytes</code>

<code>$ make -f client.mk build</code>

<code># in another shell, after the build has churned for a while:</code>
<code>$ ccache -s</code>

<code>cache directory                     /home/gps/.ccache</code>
<code>cache hit (direct)                     2</code>
<code>cache hit (preprocessed)               7 </code><code>cache miss                          2044</code>
<code>called for link                       27</code>
<code>preprocessor error                     1</code>
<code>unsupported source language            1</code>
<code>autoconf compile/link                 19</code>
<code>unsupported compiler option            4</code>
<code>files in cache                      6226</code>
<code>cache size                         659.0 Mbytes</code>
<code>max cache size                       2.0 Gbytes</code>
</pre>
<dl> <h2>Sample Performance Impact</h2> 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 <em>distclean</em>.</dl> <table border="1" cellpadding="1" cellspacing="1" style="width: 100%;"> <thead> <tr> <th scope="col"> <p>System Description</p> </th> <th scope="col"> <p>Build Type</p> </th> <th scope="col"> <p>First Build (Empty Cache)</p> </th> <th scope="col"> <p>Second Build (Populated Cache)</p> </th> <th scope="col"> <p>Change</p> </th> </tr> </thead> <tbody> <tr> <td> <ul> <li> <p>Core i7-2600K</p> </li> <li> <p>64 bit Linux VM inside Windows 7</p> </li> <li> <p>2.5GB RAM</p> </li> <li> <p>Source and cache on same spindle</p> </li> </ul> </td> <td> <ul> <li> <p>browser application</p> </li> <li> <p>-j8</p> </li> <li> <p>--enable-tests</p> </li> <li> <p>-O2</p> </li> <li> <p>mozilla-central on 2011-08-11</p> </li> </ul> </td> <td> <ul> <li> <p>17:30 wall</p> </li> <li> <p>37:04 user</p> </li> <li> <p>4:28 sys</p> </li> </ul> </td> <td> <ul> <li> <p>7:12 wall</p> </li> <li> <p>2:51 user</p> </li> <li> <p>1:04 sys</p> </li> </ul> </td> <td> <ul> <li> <p>-10:28 wall (59% faster)</p> </li> <li> <p>-34:13 user (92% faster!)</p> </li> <li> <p>-3:24 sys (76% faster)</p> </li> </ul> </td> </tr> </tbody> </table> <p>  </p><h2>Related Links</h2>  <ul> <li> <p><a class=" external" href="http://blog.lassey.us/2010/07/19/ccache-configure-option-for-mozilla/" title="http://blog.lassey.us/2010/07/19/ccache-configure-option-for-mozilla/">http://blog.lassey.us/2010/07/19/ccache-configure-option-for-mozilla/</a></p> </li> <li> <p><a class=" external" href="http://forums.mozillazine.org/viewtopic.php?f=42&amp;amp;t=405015" title="http://forums.mozillazine.org/viewtopic.php?f=42&amp;amp;t=405015">http://forums.mozillazine.org/viewtopic.php?f=42&amp;amp;t=405015</a></p> </li> <li> <p><a class=" external" href="http://weblogs.mozillazine.org/darin/archives/005504.html" title="http://weblogs.mozillazine.org/darin/archives/005504.html">http://weblogs.mozillazine.org/darin/archives/005504.html</a></p> </li> </ul>
Revert to this revision