Skip to content

Resolving deltas takes long time  #11014

Closed
@ar37-rs

Description

@ar37-rs

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 = true

Or 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/index

For Powershell users:

rm -R -Force ~\.cargo\registry\index

For Windows cmd users:

rmdir /s /q %USERPROFILE%\.cargo\registry\index

Switch 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 gitoxide for git operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions