Repository navigation
Improve CircleCI caching - #12328
Improve CircleCI caching#12328
Conversation
5e2c5d0 to
a8b649f
Compare
|
Ugh. The environment variables don't work because each run step is executed in a subshell. We'll need one of the workarounds from https://discuss.circleci.com/t/environment-variable-from-output-of-command/12196/4. |
a5f91db to
9728d45
Compare
There was a problem hiding this comment.
We could use tee here to simplify
There was a problem hiding this comment.
I'm wondering whether we really need to cache Mason packages; if not cached, they're downloaded from S3 too, which probably has a similar speed, albeit not parallelized.
There was a problem hiding this comment.
This one will only ever get triggered for rebuilds of the same gitsha, e.g. when hitting the rebuild button. Is there a way to find the previous HEAD SHA1 of the current branch?
There was a problem hiding this comment.
I don't think so. However, unless builds complete out of order, the next fallback is likely to find the desired cache, because when a key prefix finds multiple matches, the most recently written one wins.
There was a problem hiding this comment.
Hm, but that prefix marching also applies to partial SHA1 strings?
There was a problem hiding this comment.
Not sure what you mean. There's no way these keys could match part of a SHA1. If the first one doesn't match anything exactly, the second one is tried. That will match any cache for the same arch/job/branch combination, and if there are two or more matches, the most recent one will be selected.
There was a problem hiding this comment.
🤦♂️ you're right, I had my thinking backwards.
There was a problem hiding this comment.
This only tracks some of the dependencies. All platforms add additional dependencies with mason_use. E.g. Linux adds
mapbox-gl-native/platform/linux/config.cmake
Lines 1 to 11 in c1f16af
9728d45 to
0250e99
Compare
So its checksum can be used in a CI cache key name.
Save a fresh ccache on every build by including (a checksum of) the current revision in the cache key. In the worst case, saving the cache appears to take ~1:30 for android-release; other builds appear to take a small amount of time compared to the time saved by having a fresh cache, versus a cache that's up to a week old.
Restore caches in the following priority order (all scoped to current architecture and job):
1. The cache for the current branch and revision.
2. If that doesn't exist, the most recent cache for the current branch.
3. If that doesn't exist, the cache for the parent branch and merge base, where "parent branch" means the base branch of the pull request specified by $CIRCLE_PULL_REQUEST (obtained from the GitHub API), and "merge base" means the revision returned by `git merge-base` when given the parent branch and $CIRCLE_BRANCH (obtained by executing that shell command). The intent here is to start a newly created branch off with the most relevant cache from its parent branch.
4. If that doesn't exist, the most recent cache for the parent branch.
5. If that doesn't exist, the most recent cache for master.
6. If that doesn't exist, use the most recent cache for any build.
We cannot use the branch names or revisions themselves as key segments, because CircleCI lacks a way to interpolate arbitrary environment variables into the cache key name. Instead, we write the desired value into a file and use the `{{ checksum "filename" }}` syntax.
0250e99 to
adc4b04
Compare
|
A flaw with this approach is that there is no expiration mechanism for the ccache until it reaches its maximum size, so for long lived branches (e.g. The ideal behavior would be to read from the prior ccache while writing-through to a new ccache, such that the new cache contains hits from the prior ccache and the compiled results for misses. But ccache doesn't seem to offer such a mode. As far as I can tell, the best we can do is reduce the maximum size to a smaller amount -- something like the expected size of a completely fresh cache plus a small buffer -- and update that from time to time as needed. |
7eb30ac to
4cbf533
Compare
|
We could use the combination of to limit the ccache to only the files that have been used during the current build before packaging up the cache for uploading. |
Fixes #12322.
Separate node_modules, mason_packages, and cmake caches; and improve ccache freshness.
Save a fresh ccache on every build by including (a checksum of) the current revision in the cache key. In the worst case, saving the cache appears to take ~1:30 for android-release; other builds appear to take a small amount of time compared to the time saved by having a fresh cache, versus a cache that's up to a week old.
Restore caches in the following priority order (all scoped to current architecture and job):
git merge-basewhen given the parent branch and $CIRCLE_BRANCH (obtained by executing that shell command). The intent here is to start a newly created branch off with the most relevant cache from its parent branch.master.We cannot use the branch names or revisions themselves as key segments, because CircleCI lacks a way to interpolate arbitrary environment variables into the cache key name. Instead, we write the desired value into a file and use the
{{ checksum "filename" }}syntax.