Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve build caching on CI #1902

Merged
merged 4 commits into from
Nov 21, 2019
Merged

Conversation

jtgeibel
Copy link
Member

@jtgeibel jtgeibel commented Nov 16, 2019

These changes started based on a discussion over on internals. Basically, on every single build we end up touching some files and invaliding the caches. This forces Travis to compress and upload a new cache on every single build.

This PR includes several changes on CI:

  • Incremental compilation is disabled. It appears that incremental files can change even if nothing in the codebase changes.
  • Drop the target/.rustc_info.json file before caching, as it can change on each build.
  • Running cargo install for the diesel CLI acts similar to a cargo update causing changes to the index and some caches maintained under $HOME/.cargo. cargo install is now only run if the diesel binary is not on the path. The downside to this is that if we bump the .diesel_version file then Travis will not be using the exact same version as Heroku until we clear the CI cache. Since we only use this binary to run migrations and we haven't bumped versions since January, I think this change is low risk compared to the improvement.
  • Add RUSTFLAGS="-C debuginfo=0" to disable debug info, which helps shrink the cache size.

Based on my observations while putting together this PR, it looks like disabling incremental compilation has an impact on compile times, but this is small relative to the overall win on caching behavior. Additionally, our cache size has been reduced from 3948.04MB to 2439.19MB.

@rust-highfive
Copy link

r? @carols10cents

(rust_highfive has picked a reviewer for you, use r? to override)

For some reason, incremental files are changing on CI even when no code
changes.  Turning off incremental compilation should help avoid
uploading a new cache with every single build.

This commit also removes `target/.rustc_info.json` from the CI cache
The CI build cache is currently updated with every build, even if there
are no changes.  This is because running `cargo install` will update
the index causing some files under `$HOME/.cargo` to be updated,
invalidating the cache.

The drawback is that if we bump the diesel version, then the CLI will
not be automatically updated.  However, even an old version of the CLI
application is expected to be able to run our migrations on CI and the
cache can always be cleared if a new version is needed.
This is an attempt to further decrease the cache size on CI.
The change to `RUSTFLAGS` changes build hashes, so wiping the target
directory and doing a full rebuild.
@jtgeibel jtgeibel changed the title Remove target/debug/incremental/ before caching on CI Improve build caching on CI Nov 17, 2019
@jtgeibel jtgeibel marked this pull request as ready for review November 17, 2019 15:51
@jtgeibel
Copy link
Member Author

@bors: r+

Merging because the cache sizes on master and auto have grown to 9+ gigs each and this should resolve that.

@bors
Copy link
Contributor

bors commented Nov 21, 2019

📌 Commit 45675ec has been approved by jtgeibel

bors added a commit that referenced this pull request Nov 21, 2019
Improve build caching on CI

These changes started based on a discussion over on [internals](https://internals.rust-lang.org/t/evaluating-github-actions/11292/8?u=jtgeibel).  Basically, on every single build we end up touching some files and invaliding the caches.  This forces Travis to compress and upload a new cache on every single build.

This PR includes several changes on CI:

* Incremental compilation is disabled.  It appears that incremental files can change even if nothing in the codebase changes.
* Drop the `target/.rustc_info.json` file before caching, as it can change on each build.
* Running `cargo install` for the diesel CLI acts similar to a `cargo update` causing changes to the index and some caches maintained under `$HOME/.cargo`.  `cargo install` is now only run if the diesel binary is not on the path.  The downside to this is that if we bump the `.diesel_version` file then Travis will not be using the exact same version as Heroku until we clear the CI cache.  Since we only use this binary to run migrations and we haven't bumped versions since January, I think this change is low risk compared to the improvement.
* Add `RUSTFLAGS="-C debuginfo=0"` to disable debug info, which helps shrink the cache size.

Based on my observations while putting together this PR, it looks like disabling incremental compilation has an impact on compile times, but this is small relative to the overall win on caching behavior.  Additionally, our cache size has been reduced from 3948.04MB to 2439.19MB.
@bors
Copy link
Contributor

bors commented Nov 21, 2019

⌛ Testing commit 45675ec with merge 9042ebf...

@bors
Copy link
Contributor

bors commented Nov 21, 2019

☀️ Test successful - checks-travis
Approved by: jtgeibel
Pushing 9042ebf to master...

@bors bors merged commit 45675ec into rust-lang:master Nov 21, 2019
@carols10cents
Copy link
Member

Now I'm seeing 2157.20MB cache for master, and I don't see auto at all, so... yay? Not sure if auto being gone is expected (I guess we haven't run r+ since this was merged?)

Screen Shot of travis caches as I see them now

@carols10cents
Copy link
Member

Ok now that I've r+ed something I see auto at 560.20MB.

@jtgeibel
Copy link
Member Author

Yeah, I ended up manually clearing the caches for auto and master. The PR had shrunk their size, but they were still around 7G each for some reason. My best guess is that something changed on Travis that caused the hash in cache filenames to change and that those branches still had old cache files that would never be used again.

In any case, hopefully our cache size will now hover aroud 2.1GB per branch/PR, instead of 4GB.

@jtgeibel jtgeibel deleted the ci-cache-improvements branch November 23, 2019 05:10
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.

4 participants