Skip to content

Commit bbb38dc

Browse files
committed
Auto merge of #4118 - alexcrichton:hamt, r=matklad
Optimize a slew of Cargo internals Cargo has historically had very little optimization applied to it. Despite that it's pretty speedy today but there's always a desire to be faster! I've noticed Cargo being particularly sluggish on projects like Servo and rust-lang/rust, so I started profiling and found quite a few low-hanging fruit! This PR is a slew of optimizations across Cargo for various things found here and there. The banner optimizations are: * Resolution with a lock file should be basically a noop in terms of execution time now. An optimization was done to avoid cloning `Context` unless necessary, and that basically means it doesn't get cloned now! As the number 1 source of slowdown in Cargo this is the biggest improvement. * Lots of pieces in `resolve` are now `Rc<T>` for being more easily cloneable. * `Summary` now internally contains an `Rc` like `Dependency`, making it much more quickly cloneable. * `Registry` as a trait no longer returns a `Vec` but rather takes a closure to yield summaries up, removing lots of intermediate arrays. * We no longer spawn a thread for all units of "fresh work", only when we're about to spawn a process. Almost everything here was guided through profiling `./x.py build` on rust-lang/rust or `cargo build -p log` on Servo. Both of these stress "noop resolution" and the former also stresses noop builds. Runs of `./x.py build` dropped from 4 to 2 seconds (with lots of low-hanging fruit still remaining in Cargo itself) and `cargo build -p log` dropped from 1.5s to 0.3s. Massif graphs showing Cargo's memory usage also show that the peak memory usage of Cargo in a noop build of Servo dropped from 300MB to 30MB during resolution. I'm hoping that none of these optimizations makes the code less readable and/or understandable. There are no algorithmic improvements in this PR other than those transitively picked up by making clones cheaper and/or allocating less.
2 parents aab5c34 + a389d48 commit bbb38dc

32 files changed

+987
-671
lines changed

Cargo.lock

Lines changed: 38 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ libgit2-sys = "0.6"
3535
log = "0.3"
3636
num_cpus = "1.0"
3737
rustc-serialize = "0.3"
38+
scoped-tls = "0.1"
3839
semver = { version = "0.7.0", features = ["serde"] }
3940
serde = "1.0"
4041
serde_derive = "1.0"

src/bin/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[String]) -> C
337337
return Err(CliError::code(code));
338338
}
339339
}
340-
Err(CliError::new(err, 101))
340+
Err(CliError::new(err, 101))
341341
}
342342

343343
/// List all runnable commands

0 commit comments

Comments
 (0)