Open osiewicz opened 1 month ago
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
Concerns or objections to the proposal should be discussed on Zulip and formally registered here by adding a comment with the following syntax:
@rustbot concern reason-for-concern
<description of the concern>
Concerns can be lifted with:
@rustbot resolve reason-for-concern
See documentation at https://forge.rust-lang.org
cc @rust-lang/compiler @rust-lang/compiler-contributors
I've been experimenting with RDR as well. (https://github.com/exrok/spooky-rust-build). With good success, for instance changes in GPUI
that would take 26s would now take 2.6s to build.
A large chunk of time is still linking, though. Luckily another likely user of this hash would be wild
, see 2nd paragraph of https://github.com/davidlattimore/wild/issues/112#issuecomment-2336866784
This is a Major Change Proposal for "Relink, don't rebuild" (RDR), which is a shorthand for reducing the amount of crate rebuilds happening when working with large multi-crate workspaces.
Cargo issue I'm trying to resolve
Initial discussion on Cargo Zulip
Cargo implementation branch
Rustc implementation branch
Proposal
Problem
Over at Zed we've noticed that even seemingly innocent changes to the crate that has many dependents causes us to rebuild (almost) the whole world. Adding a
dbg!
statement to the body of non-inlineable function, formatting code, updating a dependency to a new minor version and such still forces us to rebuild all dependants of an affected crate.Proposed solution
I would like to experiment with exposing a public interface hash of a crate for use by cargo (and other build systems) in order to allow it to skip rebuilds of dependent crates in cases where the public interface of a crate does not change. Such hash should be digest of all items from current crate that are reachable from other crates; this includes:
The ability to skip rebuilds would come in handy on multiple occasions:
cargo build
that would benefit from this change; in particular, Rust Analyzer leans oncargo check
to obtain rustc diagnostics. Thus, if we were to incorporate that mechanism intocargo check
, we could get the same speedup within RA for free.C builds generally have a similar property, where the source file is split into the implementation (
.c
) file and header (interface) file. The dependents of a given translation unit are rebuilt only when the header file changes - changes to implementation files require just relinking, which is what we're after.Obstacles
The major challenge lies in calculating the hash - it adds burden for the maintainers who would have to be extremely cautious about what is a part of the public interface, as false positives with that feature (not detecting that the interface of a crate has changed) would lead to miscompilations, which is obviously scary. A glaring footgun with the hash is that it has to be insensitive to position of public items within source code, as otherwise the utility of this feature as a whole would be significantly diminished. [^1]
Another obstacle is that this feature would require rethinking how crate loader operates; namely, our POC ICEs whenever a new item is added/removed, as doing so shifts DefIds which are relied upon by artifacts that are not being rebuilt. For example, if a crate B depends on A and we rebuild just A, the artifact that we have for B might have its references invalidated. This is a major hurdle for us in pushing this work forward. [^1]: This is also why I've disregarded SVH, as it is position-sensitive. It also accounts for changes to private items.
Gains
In our internal experiments, RDR can slash dev
cargo build
times by as much as 50% (timings available in Cargo issue).cargo check
could potentially benefit even more, as it doesn't have to go through linking steps.cargo check --timings
after making a non-breaking change to theproject
crate in Zed could take 0.7s instead of 4.5s needed to recheck all of the dependants of this crate.Mentors or Reviewers
I don't have anyone in particular in mind.
Process
The main points of the Major Change Process are as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.