|  | 
|  | 1 | +--- | 
|  | 2 | +layout: post | 
|  | 3 | +title: "Call for testing: Cargo sparse-registry" | 
|  | 4 | +author: Arlo Siemsen | 
|  | 5 | +team: The Cargo Team <https://www.rust-lang.org/governance/teams/dev-tools#cargo> | 
|  | 6 | +--- | 
|  | 7 | + | 
|  | 8 | +The Cargo nightly [`sparse-registry`][sparse-registry] feature is ready for testing. The | 
|  | 9 | +feature causes Cargo to access the crates.io index over HTTP, rather than git. It can | 
|  | 10 | +provide a significant performance improvement, especially if the local copy of | 
|  | 11 | +the git index is out-of-date or not yet cloned. | 
|  | 12 | + | 
|  | 13 | +## Overview | 
|  | 14 | +To try it out, add the `-Z sparse-registry` flag on `nightly-2022-06-20` or newer build | 
|  | 15 | +of Cargo. For example, to update dependencies: | 
|  | 16 | + | 
|  | 17 | +``` | 
|  | 18 | +rustup update nightly | 
|  | 19 | +cargo +nightly -Z sparse-registry update | 
|  | 20 | +``` | 
|  | 21 | + | 
|  | 22 | +The feature can also be enabled by setting the environment variable | 
|  | 23 | +`CARGO_UNSTABLE_SPARSE_REGISTRY=true`. Setting this variable will have no effect on stable | 
|  | 24 | +Cargo, making it easy to opt-in for CI jobs. | 
|  | 25 | + | 
|  | 26 | +You can [leave feedback on the internals thread][internals]. | 
|  | 27 | + | 
|  | 28 | +If you see any issues [please report them on the Cargo repo][cargo]. The output of Cargo | 
|  | 29 | +with the environment variable `CARGO_LOG=cargo::sources::registry::http_remote=trace` set | 
|  | 30 | +will be helpful in debugging. | 
|  | 31 | + | 
|  | 32 | +## Details | 
|  | 33 | + | 
|  | 34 | +Accessing the index over HTTP allows crates.io to continue growing without hampering | 
|  | 35 | +performance. The current git index continues to grow as new crates are published, | 
|  | 36 | +and clients must download the entire index. The HTTP index only requires downloading | 
|  | 37 | +metadata for crates in your dependency tree.  | 
|  | 38 | + | 
|  | 39 | +The performance improvement for clients should be especially noticeable in CI | 
|  | 40 | +environments, particularly if no local cache of the index exists. | 
|  | 41 | + | 
|  | 42 | +On the server side, the HTTP protocol is much simpler to cache on a CDN, which improvies | 
|  | 43 | +scalability and reduces server load. | 
|  | 44 | + | 
|  | 45 | +The Cargo team plans to eventually make this the default way to access crates.io | 
|  | 46 | +(though the git index will remain for compatibility with older versions of Cargo and | 
|  | 47 | +external tools). `Cargo.lock` files will continue to reference the existing crates.io | 
|  | 48 | +index on GitHub to avoid churn. | 
|  | 49 | + | 
|  | 50 | +The `-Z sparse-registry` flag also enables alternative registries to be accessed over | 
|  | 51 | +HTTP. For more details, see the [tracking issue][tracking-issue]. | 
|  | 52 | + | 
|  | 53 | +## Thank you | 
|  | 54 | + | 
|  | 55 | +This project has been in the works for over 2.5 years with collaboration from the crates.io, | 
|  | 56 | +infra, and Cargo teams. | 
|  | 57 | + | 
|  | 58 | +@kornelski wrote the [sparse-index RFC][rfc] and initial performance | 
|  | 59 | +proof of concept. @jonhoo created the initial implementation in Cargo and gathered performance | 
|  | 60 | +data. @arlosi completed the implementation in Cargo and implemented the changes to crates.io | 
|  | 61 | +to serve the index. @eh2406 provided numerous reviews and feedback to get all the changes | 
|  | 62 | +landed. Many others from the community helped by providing suggestions, feedback, and testing. | 
|  | 63 | +Thank you to everyone involved! | 
|  | 64 | + | 
|  | 65 | +[rfc]: https://rust-lang.github.io/rfcs/2789-sparse-index.html | 
|  | 66 | +[sparse-registry]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#sparse-registry | 
|  | 67 | +[internals]: https://internals.rust-lang.org/t/call-for-testing-cargo-sparse-registry/16862 | 
|  | 68 | +[tracking-issue]: https://github.com/rust-lang/cargo/issues/9069 | 
|  | 69 | +[cargo]: https://github.com/rust-lang/cargo/issues | 
0 commit comments