Skip to content

Commit

Permalink
dist: Trim the manifest toml to improve startup time
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
  • Loading branch information
kinnison committed Jan 2, 2021
1 parent 0722f87 commit c356122
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/dist/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,12 +714,15 @@ fn try_update_from_dist_<'a>(
},
toolchain,
) {
Ok(Some((m, hash))) => {
Ok(Some((mut m, hash))) => {
(download.notify_handler)(Notification::DownloadedManifest(
&m.date,
m.get_rust_version().ok(),
));

m.trim(&toolchain.target);
m.validate()?;

let profile_components = match profile {
Some(profile) => m.get_profile_components(profile, &toolchain.target)?,
None => Vec::new(),
Expand Down
30 changes: 29 additions & 1 deletion src/dist/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl Manifest {
Ok(())
}

fn validate(&self) -> Result<()> {
pub fn validate(&self) -> Result<()> {
// Every component mentioned must have an actual package to download
for pkg in self.packages.values() {
match pkg.targets {
Expand Down Expand Up @@ -319,6 +319,34 @@ impl Manifest {
c
})
}

/// Trim the manifest so that it is only relevant for the given toolchain
/// target. This massively reduces the work rustup has to do to parse the
/// channel manifests in future
pub fn trim(&mut self, target: &TargetTriple) {
for (pname, package) in self.packages.iter_mut() {
if pname == "rust-std" {
// We retain all targets for rust-std since that gives us our
// rustup target add ...
continue;
}
match package.targets {
PackageTargets::Wildcard(_) => {}
PackageTargets::Targeted(ref mut targs) => {
targs.retain(|k, _| k == target);
for (_, pkg) in targs.iter_mut() {
pkg.components.retain(|comp| {
// Components of packages are retained only if they
// are rust-std (for targets) or if their target is
// either wildcarded, or matches the goal target.
comp.pkg.as_str() == "rust-std"
|| comp.target.as_ref().map(|t| t == target).unwrap_or(true)
})
}
}
}
}
}
}

impl Package {
Expand Down

0 comments on commit c356122

Please sign in to comment.