Skip to content

Commit

Permalink
Auto merge of #14318 - Eh2406:wrap_is_not_cheap, r=epage
Browse files Browse the repository at this point in the history
dont call wrap in a no-op source_id::with*

### What does this PR try to resolve?

When running resolution in parallel (which my pubgrub tests do but cargo does not) there can be a lot of contention on the lock for constructing new `source_id`. When investigating much of this is due to `without_precise` in `encodable_package_id` in `check_duplicate_pkgs_in_lockfile`. There are many ways to solve this, the simplest seems to be to return `self` if the requested modification made no difference.

### How should we test and review this PR?

All tests still pass and it's an internal re-factor.

In addition running all crates on crates.io through cargoes resolver in parallel on 190 cores went from >20k sec cpu time to ~10k.

### Additional information
  • Loading branch information
bors committed Jul 29, 2024
2 parents 46e7e83 + 22f4352 commit 62f2d3b
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,34 +468,33 @@ impl SourceId {

/// Creates a new `SourceId` from this source with the given `precise`.
pub fn with_git_precise(self, fragment: Option<String>) -> SourceId {
SourceId::wrap(SourceIdInner {
precise: fragment.map(|f| Precise::GitUrlFragment(f)),
..(*self.inner).clone()
})
self.with_precise(&fragment.map(|f| Precise::GitUrlFragment(f)))
}

/// Creates a new `SourceId` from this source without a `precise`.
pub fn without_precise(self) -> SourceId {
SourceId::wrap(SourceIdInner {
precise: None,
..(*self.inner).clone()
})
self.with_precise(&None)
}

/// Creates a new `SourceId` from this source without a `precise`.
pub fn with_locked_precise(self) -> SourceId {
SourceId::wrap(SourceIdInner {
precise: Some(Precise::Locked),
..(*self.inner).clone()
})
self.with_precise(&Some(Precise::Locked))
}

/// Creates a new `SourceId` from this source with the `precise` from some other `SourceId`.
pub fn with_precise_from(self, v: Self) -> SourceId {
SourceId::wrap(SourceIdInner {
precise: v.inner.precise.clone(),
..(*self.inner).clone()
})
self.with_precise(&v.inner.precise)
}

fn with_precise(self, precise: &Option<Precise>) -> SourceId {
if &self.inner.precise == precise {
self
} else {
SourceId::wrap(SourceIdInner {
precise: precise.clone(),
..(*self.inner).clone()
})
}
}

/// When updating a lock file on a version using `cargo update --precise`
Expand Down

0 comments on commit 62f2d3b

Please sign in to comment.