To maximize performance, it is essential to follow the recommendations in the Productivity Notes: set the base_dir
Ccache configuration option or use the CCACHE_BASEDIR
environment variable:
0$ export CCACHE_BASEDIR=$HOME
Here are examples of usage on Ubuntu 24.04:
- Across different worktrees:
0$ export CCACHE_DIR=$(mktemp -d)
1$ git worktree add ../wt_1 4d3f360e2af94f4ed46dc0943196d548da82003e
2$ pushd ../wt_1
3$ cmake -B build -DWITH_CCACHE=ON
4$ cmake --build build -t bitcoind -j $(nproc)
5$ popd
6$ git worktree add ../wt_2 4d3f360e2af94f4ed46dc0943196d548da82003e
7$ pushd ../wt_2
8$ cmake -B build -DWITH_CCACHE=ON
9$ ccache --zero-stats
10$ cmake --build build -t bitcoind -j $(nproc)
11$ popd
12$ ccache --show-stats
13Cacheable calls: 302 / 302 (100.0%)
14 Hits: 302 / 302 (100.0%)
15 Direct: 302 / 302 (100.0%)
16 Preprocessed: 0 / 302 ( 0.00%)
17 Misses: 0 / 302 ( 0.00%)
18Local storage:
19 Cache size (GiB): 0.2 / 5.0 ( 3.31%)
20 Hits: 302 / 302 (100.0%)
21 Misses: 0 / 302 ( 0.00%)
- Across different build trees:
0$ export CCACHE_DIR=$(mktemp -d)
1$ cmake -B build_1 -DWITH_CCACHE=ON
2$ cmake --build build_1 -t bitcoind -j $(nproc)
3$ cmake -B build_2 -DWITH_CCACHE=ON
4$ ccache --zero-stats
5$ cmake --build build_2 -t bitcoind -j $(nproc)
6$ ccache --show-stats
7Cacheable calls: 302 / 302 (100.0%)
8 Hits: 302 / 302 (100.0%)
9 Direct: 302 / 302 (100.0%)
10 Preprocessed: 0 / 302 ( 0.00%)
11 Misses: 0 / 302 ( 0.00%)
12Local storage:
13 Cache size (GiB): 0.2 / 5.0 ( 3.31%)
14 Hits: 302 / 302 (100.0%)
15 Misses: 0 / 302 ( 0.00%)
This PR addresses this comment:
However, ccache does not hit across two different build dirs, compiling the same commit.
Fixes #31771.
Form https://github.com/bitcoin/bitcoin/actions/runs/13215680798/job/36894673006:
0...
1Treat compiler warnings as errors ..... ON
2Use ccache for compiling .............. Built-in ccache support for the 'Visual Studio 17 2022' generator is not available.
3
4
5-- Configuring done (300.1s)
6-- Generating done (1.2s)
7-- Build files have been written to: D:/a/bitcoin/bitcoin/build