]> git.proxmox.com Git - cargo.git/commit
Auto merge of #4118 - alexcrichton:hamt, r=matklad
authorbors <bors@rust-lang.org>
Mon, 5 Jun 2017 14:49:59 +0000 (14:49 +0000)
committerbors <bors@rust-lang.org>
Mon, 5 Jun 2017 14:49:59 +0000 (14:49 +0000)
commitbbb38dce7f224c4c83d4fb9a69dfe9c783e00a4e
treee378f0ab41e599b2a8f46443e0ee5186020f8235
parentaab5c348aa396070bb22f6be2de94caf6ecd5162
parenta389d483b1ae458e89100dbfb8cfc6e33a80f88f
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.