PERF: Add ccache/sccache support to GitHub Actions CI workflows#5910
PERF: Add ccache/sccache support to GitHub Actions CI workflows#5910hjmjohnson wants to merge 3 commits intoInsightSoftwareConsortium:mainfrom
Conversation
|
On my local computer, using ccache GREATLY accelerates the build process when only a single test is modified. Touching the CMakeLists.txt files often triggers the need to rebuild 6760 object files, which takes about 30 minutes; with CCache, it is done in about 2 minutes (with mostly cache hits). I think this will be the case for many CI builds if we can get this to work. |
62410c1 to
04d71ee
Compare
04d71ee to
e5285c0
Compare
7058336 to
4f51f7e
Compare
4f51f7e to
0fc1f76
Compare
0fc1f76 to
3ccfa73
Compare
|
NOTE: Compiler object caching with very few changes can reduce the build time to under 10 minutes for builds that previously took 2 hours. |
dzenanz
left a comment
There was a problem hiding this comment.
Sounds like a great improvement.
Add hendrikmuhs/ccache-action to pixi.yml and arm.yml to cache compiled objects between CI runs. Add configure-ci pixi task that sets CMAKE_C_COMPILER_LAUNCHER and CMAKE_CXX_COMPILER_LAUNCHER to ccache; arm.yml injects the same variables via dashboard_cache. The BRAINSia/free-disk-space step leaves the apt package index stale, causing hendrikmuhs/ccache-action to fail installing ccache with exit code 100. Set update-package-index: true so the action refreshes the index before attempting the install. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
For each job across all 7 AzurePipelines yml files: - Add CCACHE_DIR variable pointing to $(Pipeline.Workspace)/.ccache - Install ccache via apt-get (Linux), brew (macOS), or choco (Windows) - Add Cache@2 task to restore/save the ccache directory keyed on Agent.OS and Build.SourceVersion with OS-only restoreKeys fallback - Inject CMAKE_C_COMPILER_LAUNCHER and CMAKE_CXX_COMPILER_LAUNCHER into dashboard_cache so the CTest dashboard configure step picks them up Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Emit STATUS not FATAL_ERROR When the compiler launcher binary reports a version matching "sccache X.Y.Z" (e.g. the binary installed by hendrikmuhs/ccache-action on Windows), emit a CMake STATUS instead of a FATAL_ERROR. sccache works as a compiler launcher but does not support CCACHE_VERSION reporting.
3ccfa73 to
1f22093
Compare
blowekamp
left a comment
There was a problem hiding this comment.
This is a great addition!!! I used to use it with CircleCI with SimpleITK, but never reimplemented in with GitHub Actions.
Please check the documentation for the hash keys, there is some tuning that can be done to better get a good cache.
We have had some disk space issues on several builds. Maybe it was just the Python builds? This may cause problems with them. It may take a couple runs for the cache to get filled, and the disk space to be come an issue. Are there any stats on the current disk usage being displayed?
| - name: Set up ccache | ||
| uses: hendrikmuhs/ccache-action@v1.2 | ||
| with: | ||
| key: ${{ matrix.os }}-${{ matrix.name }}-ccache |
There was a problem hiding this comment.
The documentation of the hash key is here:
https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching
The has key is matched from the beginning to the end, so it should start with the less specific an go to the more specific. I suggest the following:
ccache-v1-${{ matrix.os }}-${{ matrix.name }}-${{branch-name}}
Additionally with the raw action/cache there is a restore key field that can take multiple lines. This should have the above first then ccache-v1-${{ matrix.os }}-main so that is falls back to the cache on the main. I don't recall the more advance logic to get the "release" cache to work correctly for PR to the release branch.... maybe a variable for the target branch name would be appropriate as a heigher priority.
Summary
hendrikmuhs/ccache-action@v1.2topixi.yml(ubuntu, windows, macos) andarm.yml(ubuntu-arm, macos rosetta, macos Python) to cache compiled objects between CI runsconfigure-cipixi task inpyproject.tomlthat passes-DCMAKE_C_COMPILER_LAUNCHER=ccacheand-DCMAKE_CXX_COMPILER_LAUNCHER=ccacheto CMake;pixi.ymluses this task instead ofconfigurearm.ymlinjects the same cmake launcher variables viadashboard_cacheso the CTest dashboard script picks them up at configure timepixi.lockhash (pixi workflow) or OS + matrix name (arm workflow) to avoid stale cache on toolchain upgradesTest plan
pixi.yml🤖 Generated with Claude Code