Skip to content

Use ccache to cache build object files to improve build time#945

Open
Aksha1812 wants to merge 2 commits intovalkey-io:mainfrom
Aksha1812:fulltext-dev-aksha38
Open

Use ccache to cache build object files to improve build time#945
Aksha1812 wants to merge 2 commits intovalkey-io:mainfrom
Aksha1812:fulltext-dev-aksha38

Conversation

@Aksha1812
Copy link
Copy Markdown
Collaborator

@Aksha1812 Aksha1812 commented Apr 1, 2026

Using Github Actions cache included with every github repo https://github.com/actions/cache to cache C, C++ build object files with the help of ccache .

                    ┌───────────────────────┐
                    │  GitHub Actions Cache │
                    │  (free, persisted)    │
                    └───┬──────────────┬────┘
                restore │              │ save
                        ▼              │
  ┌──────────────────────────────────────────────┐
  │  CI Build                                    │
  │                                              │
  │  file.cc ──► ccache ──► HIT?  ──YES──►  .o   │
  │                           │                  │
  │                           NO                 │
  │                           │                  │
  │                       compile ──────►  .o    │
  └──────────────────────────────────────────────┘

  Push 1 (cold):  166 compiled, 0 cached      ~16 min
  Push 2 (warm):  3 compiled, 163 cached       ~4 min

The cache is saved under a unique key per commit (key: ccache-...-${{ github.ref }}-${{ github.sha }}). On restore, if the exact key isn't found (new commit), restore-keys falls back to the most recent cache from the same branch (ccache-...-${{ github.ref }}-), and if that doesn't exist either (new branch), falls back to any previous cache for that workflow (ccache-...-). This means a new PR automatically inherits the cache from its base branch, and subsequent pushes to the same PR reuse the previous push's cache. And older keys are automatically evicted.


For example for unitests workflow you can Attempt # 1 took 22 minutes https://github.com/valkey-io/valkey-search/actions/runs/23844443858/attempts/1?pr=945

In Restore cache workflow you can see

Run actions/cache@v4
Cache not found for input keys: ccache-unittests-refs/pull/945/merge-266d14f448b0593f949c7cf62e66f2490ac87965, ccache-unittests-refs/pull/945/merge-, ccache-unittests-

I raran the workflow. For Attempt # 2 it took only 6 minutes https://github.com/valkey-io/valkey-search/actions/runs/23844443858/attempts/2?pr=945 . Since there was no file diff between the two attempts we were able to reuse all the cached build output file, so only steps remaining were docker build, icu build, linking and running unit tests

In Restore cache workflow you can see

Run actions/cache@v4
Cache hit for: ccache-unittests-refs/pull/945/merge-266d14f448b0593f949c7cf62e66f2490ac87965
Received 0 of 395856534 (0.0%), 0.0 MBs/sec
Received 113246208 of 395856534 (28.6%), 54.0 MBs/sec
Received 247463936 of 395856534 (62.5%), 78.6 MBs/sec
Received 391662230 of 395856534 (98.9%), 93.3 MBs/sec
Received 395856534 of 395856534 (100.0%), 93.5 MBs/sec
Cache Size: ~378 MB (395856534 B)
/usr/bin/tar -xf /home/runner/work/_temp/6db92834-8b4a-4e89-99ee-06be954256d1/cache.tzst -P -C /home/runner/work/valkey-search/valkey-search --use-compress-program unzstd
Cache restored successfully
Cache restored from key: ccache-unittests-refs/pull/945/merge-266d14f448b0593f949c7cf62e66f2490ac87965

Earlier build typically took 17 minutes, after this change it will take any time between 2-4 min assuming average number of files changed around 5-10 per change . Improving build time by 70-80% . And overall workflow time by 50-60%

Signed-off-by: Aksha Thakkar <thaakb@amazon.com>
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.

[FEATURE] Improve valkey-search build time

1 participant