mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
Avoid serializing if lockfile does not change (#4945)
## Summary Avoid serializing and writing the lockfile if a cheap comparison shows that the contents have not changed. ## Test Plan Shaves ~10ms off of https://github.com/astral-sh/uv/issues/4860 for me. ``` ➜ transformers hyperfine "../../uv/target/profiling/uv lock" "../../uv/target/profiling/baseline lock" --warmup 3 Benchmark 1: ../../uv/target/profiling/uv lock Time (mean ± σ): 130.5 ms ± 2.5 ms [User: 130.3 ms, System: 85.0 ms] Range (min … max): 126.8 ms … 136.9 ms 23 runs Benchmark 2: ../../uv/target/profiling/baseline lock Time (mean ± σ): 140.5 ms ± 5.0 ms [User: 142.8 ms, System: 85.5 ms] Range (min … max): 133.2 ms … 153.3 ms 21 runs Summary ../../uv/target/profiling/uv lock ran 1.08 ± 0.04 times faster than ../../uv/target/profiling/baseline lock ```
This commit is contained in:
parent
dc80fdba2c
commit
8c9bd70c71
3 changed files with 34 additions and 15 deletions
|
@ -38,7 +38,7 @@ use crate::{RequiresPython, ResolutionGraph};
|
|||
/// The current version of the lock file format.
|
||||
const VERSION: u32 = 1;
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
#[derive(Clone, Debug, serde::Deserialize, PartialEq, Eq)]
|
||||
#[serde(try_from = "LockWire")]
|
||||
pub struct Lock {
|
||||
version: u32,
|
||||
|
@ -514,7 +514,7 @@ impl TryFrom<LockWire> for Lock {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Distribution {
|
||||
pub(crate) id: DistributionId,
|
||||
sdist: Option<SourceDist>,
|
||||
|
@ -1321,12 +1321,15 @@ enum SourceWire {
|
|||
subdirectory: Option<String>,
|
||||
},
|
||||
Path {
|
||||
#[serde(deserialize_with = "deserialize_path_with_dot")]
|
||||
path: PathBuf,
|
||||
},
|
||||
Directory {
|
||||
#[serde(deserialize_with = "deserialize_path_with_dot")]
|
||||
directory: PathBuf,
|
||||
},
|
||||
Editable {
|
||||
#[serde(deserialize_with = "deserialize_path_with_dot")]
|
||||
editable: PathBuf,
|
||||
},
|
||||
}
|
||||
|
@ -1430,7 +1433,7 @@ enum GitSourceKind {
|
|||
}
|
||||
|
||||
/// Inspired by: <https://discuss.python.org/t/lock-files-again-but-this-time-w-sdists/46593>
|
||||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
#[derive(Clone, Debug, serde::Deserialize, PartialEq, Eq)]
|
||||
struct SourceDistMetadata {
|
||||
/// A hash of the source distribution.
|
||||
hash: Hash,
|
||||
|
@ -1444,7 +1447,7 @@ struct SourceDistMetadata {
|
|||
/// locked against was found. The location does not need to exist in the
|
||||
/// future, so this should be treated as only a hint to where to look
|
||||
/// and/or recording where the source dist file originally came from.
|
||||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
#[derive(Clone, Debug, serde::Deserialize, PartialEq, Eq)]
|
||||
#[serde(untagged)]
|
||||
enum SourceDist {
|
||||
Url {
|
||||
|
@ -1695,7 +1698,7 @@ fn locked_git_url(git_dist: &GitSourceDist) -> Url {
|
|||
}
|
||||
|
||||
/// Inspired by: <https://discuss.python.org/t/lock-files-again-but-this-time-w-sdists/46593>
|
||||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
#[derive(Clone, Debug, serde::Deserialize, PartialEq, Eq)]
|
||||
#[serde(try_from = "WheelWire")]
|
||||
struct Wheel {
|
||||
/// A URL or file path (via `file://`) where the wheel that was locked
|
||||
|
@ -2047,7 +2050,7 @@ impl From<Dependency> for DependencyWire {
|
|||
///
|
||||
/// A hash is encoded as a single TOML string in the format
|
||||
/// `{algorithm}:{digest}`.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
struct Hash(HashDigest);
|
||||
|
||||
impl From<HashDigest> for Hash {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue