<p>The tool ccache helps store intermediate compilation results, so if you change branches often, and rebuild, it can significantly speed up doing so.</p>
<p>To use it, you install <code>ccache</code> for your platform. That's it. The Bitcoin Core configure script will detect its presence, and use it automatically.</p>

CC BY-SA 4.0
2020-09-19T01:29:22.110Z
2023-09-06T20:34:11.480Z
2023-09-06T20:34:11.480Z
Pieter Wuille
<p><a href="https://ccache.dev/" rel="nofollow noreferrer">ccache</a> is a compiler cache.</p>
<blockquote>
<p>It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again.</p>
</blockquote>
<p>Unlike <a href="https://bitcoin.stackexchange.com/questions/89100/bitcoind-node-crashes-after-using-dbcache-option">dbcache</a> the decision of how much ccache to allocate is not as critical. The Bitcoin Core productivity <a href="https://github.com/bitcoin/bitcoin/blob/492cdc56e087c7f51f3d1e3f807191da7f9d9a07/doc/productivity.md#cache-compilations-with-ccache" rel="nofollow noreferrer">doc</a> does recommend that you put something like this in <code>~/.ccache/ccache.conf</code>:</p>
<pre><code>max_size = 50.0G  # or whatever cache size you prefer; default is 5G; 0 means unlimited

base_dir = /home/yourname  # or wherever you keep your source files
</code></pre>
<blockquote>
<p>Note: base_dir is required for ccache to share cached compiles of the
same file across different repositories / paths; it will only do this
for paths under base_dir. So this option is required for effective use
of ccache with git worktrees.</p>
<p>You must not set base_dir to &quot;/&quot;, or anywhere that contains system
headers (according to the ccache docs).</p>
</blockquote>
<p>There doesn't appear to be any obvious downsides to use <code>ccache</code>. But there are a couple of warnings on the ccache <a href="https://ccache.dev/" rel="nofollow noreferrer">site</a>.</p>
<blockquote>
<p>Compilers are moving targets. Newer compiler versions may, and often
do, introduce features that ccache can't foresee.</p>
</blockquote>
<p>and</p>
<blockquote>
<p>The fastest mode (the &quot;direct mode&quot;) has a corner case which can result in false positive cache hits.</p>
</blockquote>
<p>Generally though it appears you can just install it (as Pieter says) and forget about it and this will save you time on compiling Bitcoin Core PRs.</p>
<p>For other information on speeding up C++ compilation see this excellent blog <a href="https://codingnest.com/the-little-things-speeding-up-c-compilation/" rel="nofollow noreferrer">post</a> from Martin Hořeňovský.</p>

CC BY-SA 4.0
2020-09-20T14:35:40.240Z
2020-09-21T09:40:14.123Z
2020-09-21T09:40:14.123Z
Michael Folkson
<p>What is <a href="https://github.com/bitcoin/bitcoin/blob/492cdc56e087c7f51f3d1e3f807191da7f9d9a07/doc/productivity.md#cache-compilations-with-ccache" rel="nofollow noreferrer">ccache</a>? Can you provide some guidance on when to use it for building Bitcoin Core PRs and how to use it?</p>

<bitcoin-core-development><compiling><bitcoincore-review><cache>
What is ccache? When should I use it when building and reviewing Bitcoin Core PRs?
Michael Folkson
# What is ccache? When should I use it when building and reviewing Bitcoin Core PRs?

(Asked by: username_0 on 2020-09-18)

What is [ccache](https://github.com/bitcoin/bitcoin/blob/492cdc56e087c7f51f3d1e3f807191da7f9d9a07/doc/productivity.md#cache-compilations-with-ccache)? Can you provide some guidance on when to use it for building Bitcoin Core PRs and how to use it?

**Tags:** bitcoin-core-development, compiling, bitcoincore-review, cache


---

## 2 answers

### Answer by username_1 on 2020-09-19. Score: 3 | Accepted answer

The tool ccache helps store intermediate compilation results, so if you change branches often, and rebuild, it can significantly speed up doing so.

To use it, you install `ccache` for your platform. That's it. The Bitcoin Core configure script will detect its presence, and use it automatically.


---

### Answer by username_0 on 2020-09-20. Score: 1

[ccache](https://ccache.dev/) is a compiler cache.

> It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again.

Unlike [dbcache](https://bitcoin.stackexchange.com/questions/89100/bitcoind-node-crashes-after-using-dbcache-option) the decision of how much ccache to allocate is not as critical. The Bitcoin Core productivity [doc](https://github.com/bitcoin/bitcoin/blob/492cdc56e087c7f51f3d1e3f807191da7f9d9a07/doc/productivity.md#cache-compilations-with-ccache) does recommend that you put something like this in `~/.ccache/ccache.conf`:

```
max_size = 50.0G  # or whatever cache size you prefer; default is 5G; 0 means unlimited

base_dir = /home/yourname  # or wherever you keep your source files

```

> Note: base\_dir is required for ccache to share cached compiles of the
> same file across different repositories / paths; it will only do this
> for paths under base\_dir. So this option is required for effective use
> of ccache with git worktrees.
>
> You must not set base\_dir to "/", or anywhere that contains system
> headers (according to the ccache docs).

There doesn't appear to be any obvious downsides to use `ccache`. But there are a couple of warnings on the ccache [site](https://ccache.dev/).

> Compilers are moving targets. Newer compiler versions may, and often
> do, introduce features that ccache can't foresee.

and

> The fastest mode (the "direct mode") has a corner case which can result in false positive cache hits.

Generally though it appears you can just install it (as username_1 says) and forget about it and this will save you time on compiling Bitcoin Core PRs.

For other information on speeding up C++ compilation see this excellent blog [post](https://codingnest.com/the-little-things-speeding-up-c-compilation/) from Martin Hořeňovský.


---

