Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information