rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.57k stars 2.38k forks source link

Loading of a git source is slow due to manifest parsing #14395

Open epage opened 1 month ago

epage commented 1 month ago

When you have some git dependencies or patches, loading them takes a long time

For the traces from #14238, notice how slow the first resolve is compared to the second. Almost all of that is taken up in Manifest parsing image

Note: this slow down is most relevant for tooling like rust-analyzer or rust-defined completions when it may be called in interactive contexts without any compilation happening.

Related: #13724

epage commented 1 month ago

Previously discussed at https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Redundant.20code.20in.20.60GitSouce.60.3F

epage commented 1 month ago

The core problem is that git sources are indexed by name. To find a name, we walk the source to find all Cargo.toml files except if they are in a submodule or a hidden directory except if a Cargo.toml has a path dependency in it in an ignored location.

Without that second exception, we could parse Cargo.toml to toml::Table, look up the name, and be done. That would cut out probably 60% of the manifest parsing performance hit.

With the second exception, we have to do a full parse of the Cargo.toml file.

Ideas

epage commented 1 month ago

Main risk: there aren't enough manifests for us to skip loading