Skip to content

Add caching layer to bootstrap #142816

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

Merged

Conversation

Shourya742
Copy link
Contributor

This PR adds a caching layer to the bootstrap command execution context. It is still a work in progress but introduces the initial infrastructure for it.

r? @Kobzol

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Jun 21, 2025
Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I haven't checked the code yet, but once you get it working, it would be great to see some benchmarks. Ideally of "no-op" commands, like running x check rustc after no change has been made to the compiler.

@rust-log-analyzer

This comment has been minimized.

@Shourya742 Shourya742 requested a review from Kobzol June 24, 2025 05:43
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 24, 2025
Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you misunderstood what I meant and went in a different direction, sorry :) I tried to clarify in comments.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from cf6a2c5 to cd9224f Compare June 24, 2025 11:57
Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that std::process::Command now provides a way to return all the inner state regarding arguments, env. variables, program and workdir. In that case, we don't need to store the cache key at all, and we can just reconstruct it from the inner std Command right before executing the bootstrap command.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from 0f9af82 to 043d094 Compare June 24, 2025 15:47
@Shourya742 Shourya742 marked this pull request as ready for review June 24, 2025 15:54
@rust-log-analyzer

This comment has been minimized.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from 043d094 to 821d695 Compare June 24, 2025 16:18
@Shourya742 Shourya742 requested a review from Kobzol June 24, 2025 16:20
@rust-log-analyzer

This comment has been minimized.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from 821d695 to f40c002 Compare June 24, 2025 16:46
@rust-log-analyzer

This comment has been minimized.

@Kobzol
Copy link
Contributor

Kobzol commented Jun 24, 2025

Seems like some cache hits are being encountered, that's good. Later it would be nice to also record the durations of individual commands and then print some statistics at the end, which commands took the longest to execute, how many cache hits/misses they had etc.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from f40c002 to 5735674 Compare June 24, 2025 17:14
@Kobzol
Copy link
Contributor

Kobzol commented Jun 24, 2025

Code looks good now, but before we merge it, I think that we should go through existing commands and make sure that it won't be problematic to cache them. I'll go through bootstrap tomorrow and check.

It would also be useful to add a comment on top of BootstrapCommand that explains that by default, command executions are cached if they have the same workdir/program/args/envs.

@Shourya742
Copy link
Contributor Author

Shourya742 commented Jun 24, 2025

Code looks good now, but before we merge it, I think that we should go through existing commands and make sure that it won't be problematic to cache them. I'll go through bootstrap tomorrow and check.

It would also be useful to add a comment on top of BootstrapCommand that explains that by default, command executions are cached if they have the same workdir/program/args/envs.

I will add that.. added here: a5df236

@rust-log-analyzer

This comment has been minimized.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from a5df236 to bebe11d Compare June 24, 2025 17:58
@Shourya742 Shourya742 requested a review from Kobzol June 24, 2025 19:23
@Kobzol Kobzol mentioned this pull request Jun 25, 2025
@Kobzol
Copy link
Contributor

Kobzol commented Jun 25, 2025

Just to be sure, use do_not_cache on the command created in the bare_cargo function, to make sure that we don't ever cache cargo.

Also, it's a big edge case, but calling as_command_mut in ExecutionContext::start disables the caching of the command. Since our API allows executing the same command twice (although we don't currently do it anywhere, AFAIK), it could be cached in the first execution, and then not cached in the other executions, which is confusing. So it would be better if the execution context didn't call the function and just accessed the inner command directly. At the same time, I noticed that we have both exec.rs and execution_context.rs, which is a bit duplicated, both the command and the execution context belong together. So I would suggest moving the execution context to the exec.rs file (and remove execution_context.rs), which will also allow the context to access the inner std command without going through the as_command_mut function.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from b7ad1eb to ec765c3 Compare June 25, 2025 15:55
@Kobzol
Copy link
Contributor

Kobzol commented Jun 25, 2025

Let's see.

@bors r+ rollup=never

@bors
Copy link
Collaborator

bors commented Jun 25, 2025

📌 Commit ec765c3 has been approved by Kobzol

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 25, 2025
@bors
Copy link
Collaborator

bors commented Jun 27, 2025

☔ The latest upstream changes (presumably #143074) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 27, 2025
@workingjubilee
Copy link
Member

Nudging this forward a bit so this doesn't have to endure too much bitrot.
@bors p=1

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from ec765c3 to 591df6c Compare June 27, 2025 05:20
@Kobzol
Copy link
Contributor

Kobzol commented Jun 27, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 27, 2025

📌 Commit 591df6c has been approved by Kobzol

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 27, 2025
@bors
Copy link
Collaborator

bors commented Jun 27, 2025

⌛ Testing commit 591df6c with merge d51b6f9...

@bors
Copy link
Collaborator

bors commented Jun 27, 2025

☀️ Test successful - checks-actions
Approved by: Kobzol
Pushing d51b6f9 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 27, 2025
@bors bors merged commit d51b6f9 into rust-lang:master Jun 27, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jun 27, 2025
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing df32e15 (parent) -> d51b6f9 (this PR)

Test differences

No test diffs found

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard d51b6f97122671c5de27cfc08cded235357e0d97 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-apple-1: 6529.1s -> 8062.9s (23.5%)
  2. x86_64-apple-2: 4798.5s -> 4098.2s (-14.6%)
  3. dist-apple-various: 6707.4s -> 7470.2s (11.4%)
  4. mingw-check-1: 1742.2s -> 1549.3s (-11.1%)
  5. x86_64-gnu-tools: 3686.3s -> 3293.9s (-10.6%)
  6. x86_64-rust-for-linux: 2791.5s -> 2510.8s (-10.1%)
  7. i686-gnu-2: 6134.3s -> 5527.6s (-9.9%)
  8. x86_64-gnu-llvm-20-1: 3603.5s -> 3284.1s (-8.9%)
  9. aarch64-gnu: 6806.6s -> 6205.7s (-8.8%)
  10. x86_64-gnu-llvm-19-1: 3653.3s -> 3331.7s (-8.8%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend A-rustdoc-search Area: Rustdoc's search feature A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants