The Cargo nightly sparse-registry
feature is ready for testing. The
feature causes Cargo to access the crates.io index over HTTP, rather than git. It can
provide a significant performance improvement, especially if the local copy of
the git index is out-of-date or not yet cloned.
Overview
To try it out, add the -Z sparse-registry
flag on nightly-2022-06-20
or newer build
of Cargo. For example, to update dependencies:
rustup update nightly
cargo +nightly -Z sparse-registry update
The feature can also be enabled by setting the environment variable
CARGO_UNSTABLE_SPARSE_REGISTRY=true
. Setting this variable will have no effect on stable
Cargo, making it easy to opt-in for CI jobs.
You can leave feedback here on the internals thread.
If you see any issues please report them on the Cargo repo. The output of Cargo
with the environment variable CARGO_LOG=cargo::sources::registry::http_remote=trace
set
will be helpful in debugging.
Details
Accessing the index over HTTP allows crates.io to continue growing without hampering performance. The current git index continues to grow as new crates are published, and clients must download the entire index. The HTTP index only requires downloading metadata for crates in your dependency tree.
The performance improvement for clients should be especially noticeable in CI environments, particularly if no local cache of the index exists.
On the server side, the HTTP protocol is much simpler to cache on a CDN, which improvies scalability and reduces server load.
The Cargo team plans to eventually make this the default way to access crates.io
(though the git index will remain for compatibility with older versions of Cargo and
external tools). Cargo.lock
files will continue to reference the existing crates.io
index on GitHub to avoid churn.
The -Z sparse-registry
flag also enables alternative registries to be accessed over
HTTP. For more details, see the tracking issue.