Skip to content

Commit 62f2d3b

Browse files
committed
Auto merge of #14318 - Eh2406:wrap_is_not_cheap, r=epage
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
2 parents 46e7e83 + 22f4352 commit 62f2d3b

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/cargo/core/source_id.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -468,34 +468,33 @@ impl SourceId {
468468

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

477474
/// Creates a new `SourceId` from this source without a `precise`.
478475
pub fn without_precise(self) -> SourceId {
479-
SourceId::wrap(SourceIdInner {
480-
precise: None,
481-
..(*self.inner).clone()
482-
})
476+
self.with_precise(&None)
483477
}
484478

485479
/// Creates a new `SourceId` from this source without a `precise`.
486480
pub fn with_locked_precise(self) -> SourceId {
487-
SourceId::wrap(SourceIdInner {
488-
precise: Some(Precise::Locked),
489-
..(*self.inner).clone()
490-
})
481+
self.with_precise(&Some(Precise::Locked))
491482
}
492483

493484
/// Creates a new `SourceId` from this source with the `precise` from some other `SourceId`.
494485
pub fn with_precise_from(self, v: Self) -> SourceId {
495-
SourceId::wrap(SourceIdInner {
496-
precise: v.inner.precise.clone(),
497-
..(*self.inner).clone()
498-
})
486+
self.with_precise(&v.inner.precise)
487+
}
488+
489+
fn with_precise(self, precise: &Option<Precise>) -> SourceId {
490+
if &self.inner.precise == precise {
491+
self
492+
} else {
493+
SourceId::wrap(SourceIdInner {
494+
precise: precise.clone(),
495+
..(*self.inner).clone()
496+
})
497+
}
499498
}
500499

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

0 commit comments

Comments
 (0)