Skip to content

Commit

Permalink
Remove [u64; 4] from small version to move Arc to full version
Browse files Browse the repository at this point in the history
Cloning and dropping the version arc took a significant fraction of the time in the resolver, which is a large overhead especially for the small variant that has only 9 bytes payload.

When moving the `Arc` to only apply to the full variant, the small variant is too large because it stores a `[u64; 4]` to have a release accessor a `&[u64]` that's shared with the `Vec<u64>` of the full variant. We proxy this by first extracting the compressed version digits of the small variant to a proxy type that stores up to 4 u64 on the stack and can be deref'ed to the existing `&[u64]`, minimizing churn.

```
$ Benchmark 1: target/profiling/uv pip compile scripts/requirements/airflow.in
    Time (mean ± σ):     361.3 ms ±   2.7 ms    [User: 503.4 ms, System: 174.9 ms]
    Range (min … max):   356.3 ms … 365.2 ms    10 runs

  Benchmark 2: ./uv-3 pip compile scripts/requirements/airflow.in
    Time (mean ± σ):     402.9 ms ±   8.5 ms    [User: 571.2 ms, System: 196.6 ms]
    Range (min … max):   393.9 ms … 418.0 ms    10 runs

  Summary
    target/profiling/uv pip compile scripts/requirements/airflow.in ran
      1.12 ± 0.03 times faster than ./uv-3 pip compile scripts/requirements/airflow.in
```
  • Loading branch information
konstin committed Jan 7, 2025
1 parent eb6ad9a commit 64a8980
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 96 deletions.
4 changes: 2 additions & 2 deletions crates/uv-distribution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,8 +1343,8 @@ mod test {
/// Ensure that we don't accidentally grow the `Dist` sizes.
#[test]
fn dist_size() {
assert!(size_of::<Dist>() <= 336, "{}", size_of::<Dist>());
assert!(size_of::<BuiltDist>() <= 336, "{}", size_of::<BuiltDist>());
assert!(size_of::<Dist>() <= 352, "{}", size_of::<Dist>());
assert!(size_of::<BuiltDist>() <= 352, "{}", size_of::<BuiltDist>());
assert!(
size_of::<SourceDist>() <= 264,
"{}",
Expand Down
Loading

0 comments on commit 64a8980

Please sign in to comment.