-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Problem
Cargo can be very slow updating the crates.io index. You may see a progress bar such as:
Updating crates.io index
Fetch [=================> ] 74.01%, (64415/95919) resolving deltas
Workaround
There are three different workarounds for this issue. The following instruction assume that CARGO_HOME is the default of .cargo in your home directory.
Use net.git-fetch-with-cli
The net.git-fetch-with-cli config option will instruct cargo to use the git CLI to update the index instead of its built-in git client. The git CLI should be more efficient at updating the repository. Enter the following into your global cargo configuration file, usually ~/.cargo/config.toml (or ~/.cargo/config for older setups):
[net]
git-fetch-with-cli = trueOr set the environment variable CARGO_NET_GIT_FETCH_WITH_CLI=true.
Delete the index cache
To work around this issue, delete the existing git index in cargo's cache. This will cause cargo to re-download the index which should have minimal deltas to resolve.
For most users, the following should be sufficient:
rm -rf ~/.cargo/registry/indexFor Powershell users:
rm -R -Force ~\.cargo\registry\indexFor Windows cmd users:
rmdir /s /q %USERPROFILE%\.cargo\registry\indexSwitch to the sparse protocol
Warning: This is only available starting in 1.68 (to be released 2023-03-09). Due to a config issue, older releases will forbid setting this option.
In the 1.68 release of Rust, you can opt-in to the new sparse protocol. This uses HTTPS instead of git to update the index, which should be much more efficient in most cases. In your global ~/.cargo/config.toml file, enter:
[registries.crates-io]
protocol = "sparse"Or set the CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse environment variable.
Cause
Cargo uses the libgit2 library for handling git operations. Its "delta resolution" algorithm has some inefficiencies, particularly when updating an existing repository that has a chain of historic updates. This issue is tracked upstream in libgit2/libgit2#4674.
Solutions
There are several approaches that the Cargo Team is investigating for resolving this:
- Enabling the sparse protocol by default.
- Improving the delta resolution algorithm in libgit2.
- More aggressively garbage-collecting or deleting the git index when it grows too large.
- Switching to
gitoxidefor git operations.