c++macosgithub-actionsccache

Ccache hit rate 0.00 % in GitHub Actions CI


In our C++ project, we managed to setup GitHub Actions building our sources using ccache.

It works very well on Linux where, thanks to ccache, the build succeeds in less than 5 minutes.

Unfortunately, when trying to build on macOS, ccache doesn't seem to work, giving:

cache directory                     /Users/runner/.ccache
primary config                      /Users/runner/.ccache/ccache.conf
secondary config      (readonly)    /usr/local/Cellar/ccache/3.7.11_1/etc/ccache.conf
stats updated                       Sun Aug 23 11:57:31 2020
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                          7175
cache hit rate                      0.00 %
cache file missing                     1
cleanups performed                  2976
files in cache                       165
cache size                         422.4 MB
max cache size                     500.0 MB

AzerothCore macOS ccache issue

Consequently, the macOS build takes about 40 minutes to finish.

So despite I've tried to setup the macOS build the same way of the ubuntu-* ones, I've failed to get ccache properly working and I can't figure out why.

How to make ccache work with macOS too?


Solution

  • The problem is most likely that max cache size is too small. If the results (mostly object files) from a build do not fit in max cache size then no usable results will be left for the next build and you will only get cache misses.

    cleanups performed was 2976 before the build and 3353 after the build, so 377 automatic cleanups were performed. Since max cache size was 500 MB, each cleanup removed around 500 * (1 - 0.8) / 16 MB = 6.25 MB and all cleanups together therefore removed around 377 * 6.25 MB ≈ 2356 MB of data. That should be approximately the size of the results of one build. (0.8 is the default "limit_multiple" and 16 refers to the number of subdirectories in the cache.)

    Try to increase the cache size limit substantially. Based on the above calculation, a good cache size would be at least 5 GB. You could also or alternatively enable compression (CCACHE_COMPRESS=1) to fit more results in the cache.