Skip to content

Conversation

@ericonr
Copy link
Member

@ericonr ericonr commented Feb 25, 2025

Using ccache can speed up local rebuilds even when the container layer cache is invalidated, which is easy to happen. It also requires a less complicated and less fragile setup than distcc (though distcc will always make for faster first builds).

install_epics.sh still supports ccache-less setups, should that be required.

On my machine, building an image with ccache for the first time took ~15m. Rebuilding it after invalidating the layer cache took only 3m36s. The output of 'ccache -s' is reproduced below:

Cacheable calls:   3858 / 8743 (44.13%)
  Hits:            1923 / 3858 (49.84%)
    Direct:        1822 / 1923 (94.75%)
    Preprocessed:   101 / 1923 ( 5.25%)
  Misses:          1935 / 3858 (50.16%)
Uncacheable calls: 4885 / 8743 (55.87%)
Local storage:
  Cache size (GB): 0.18 / 5.00 ( 3.70%)

It is not clear why the cache hits were below 50%, but it was still enough to make a big difference in build times.

This was based on StackOverflow [1].

[1] https://stackoverflow.com/a/56833198

Using ccache can speed up local rebuilds even when the container layer
cache is invalidated, which is easy to happen. It also requires a less
complicated and less fragile setup than distcc (though distcc will
always make for faster first builds).

install_epics.sh still supports ccache-less setups, should that be
required.

On my machine, building an image with ccache for the first time took
~15m. Rebuilding it after invalidating the layer cache took only 4m06s.
The output of 'ccache -s' is reproduced below:

    Cacheable calls:   1929 / 4371 (44.13%)
      Hits:            1923 / 1929 (99.69%)
        Direct:        1829 / 1923 (95.11%)
        Preprocessed:    94 / 1923 ( 4.89%)
      Misses:             6 / 1929 ( 0.31%)
    Uncacheable calls: 2442 / 4371 (55.87%)
    Local storage:
      Cache size (GB): 0.19 / 5.00 ( 3.71%)

This was based on StackOverflow [1], but adding the compiler symlinks to
/usr/local/bin wasn't enough for the EPICS build system to use them,
since it uses fully qualified paths. Therefore, it was necessary to
override the paths in configure/CONFIG.gnuCommon (appending to the file
was the easiest way to override them for sure). We also had to call
'ccache -z' to remove the ccache statistics file, otherwise it would
roll over for each build and mix data from different builds.

[1] https://stackoverflow.com/a/56833198
@ericonr
Copy link
Member Author

ericonr commented Feb 26, 2025

I'm using ARG for CCACHE_DIR, but maybe I should use ENV, so building IOC images still uses a well defined path instead of the $HOME/.config/ccache default (based on https://ccache.dev/manual/4.10.2.html#_configuration_options).

Having those files in the build image shouldn't be an issue anyway, since all our images use multi-stage builds with copies into a clean image.

@henriquesimoes
Copy link
Collaborator

I'm using ARG for CCACHE_DIR, but maybe I should use ENV

In fact, it doesn't make much sense to have it as an ARG if --mount won't have any different path than the one predefined by us.

Having those files in the build image shouldn't be an issue anyway, since all our images use multi-stage builds with copies into a clean image.

I'm not sure I grasped which files you're referring to. Are you talking about not defining ENV at all and letting it write to $HOME/.config/ccache?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Evaluate ccache and a bind volume to speed up offline base builds

3 participants