mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-26 12:09:12 +00:00
Use async unzip for local source distributions (#1809)
## Summary We currently maintain separate untar methods for sync and async, but we only use the sync version when the user provides a local source distribution. (Otherwise, we untar as we download the distribution.) In my testing, this is actually slower anyway: ``` ❯ python -m scripts.bench \ --uv-path ./target/release/main \ --uv-path ./target/release/uv \ ./requirements.in --benchmark resolve-cold --min-runs 50 Benchmark 1: ./target/release/main (resolve-cold) Time (mean ± σ): 835.2 ms ± 107.4 ms [User: 346.0 ms, System: 151.3 ms] Range (min … max): 639.2 ms … 1051.0 ms 50 runs Benchmark 2: ./target/release/uv (resolve-cold) Time (mean ± σ): 750.7 ms ± 91.9 ms [User: 345.7 ms, System: 149.4 ms] Range (min … max): 637.9 ms … 905.7 ms 50 runs Summary './target/release/uv (resolve-cold)' ran 1.11 ± 0.20 times faster than './target/release/main (resolve-cold)' ```
This commit is contained in:
parent
a2a1b2fb0f
commit
88a0c13865
5 changed files with 3 additions and 51 deletions
|
@ -20,7 +20,6 @@ fs-err = { workspace = true, features = ["tokio"] }
|
|||
futures = { workspace = true }
|
||||
rayon = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
tar = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
tokio = { workspace = true, features = ["io-util"] }
|
||||
tokio-tar = { workspace = true }
|
||||
|
|
|
@ -73,42 +73,6 @@ pub fn unzip<R: Send + std::io::Read + std::io::Seek + HasLength>(
|
|||
.collect::<Result<_, Error>>()
|
||||
}
|
||||
|
||||
/// Extract a `.zip` or `.tar.gz` archive into the target directory.
|
||||
pub fn archive(source: impl AsRef<Path>, target: impl AsRef<Path>) -> Result<(), Error> {
|
||||
// `.zip`
|
||||
if source
|
||||
.as_ref()
|
||||
.extension()
|
||||
.is_some_and(|ext| ext.eq_ignore_ascii_case("zip"))
|
||||
{
|
||||
unzip(fs_err::File::open(source.as_ref())?, target.as_ref())?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// `.tar.gz`
|
||||
if source
|
||||
.as_ref()
|
||||
.extension()
|
||||
.is_some_and(|ext| ext.eq_ignore_ascii_case("gz"))
|
||||
{
|
||||
if source.as_ref().file_stem().is_some_and(|stem| {
|
||||
Path::new(stem)
|
||||
.extension()
|
||||
.is_some_and(|ext| ext.eq_ignore_ascii_case("tar"))
|
||||
}) {
|
||||
let mut archive = tar::Archive::new(flate2::read::GzDecoder::new(fs_err::File::open(
|
||||
source.as_ref(),
|
||||
)?));
|
||||
// https://github.com/alexcrichton/tar-rs/issues/349
|
||||
archive.set_preserve_mtime(false);
|
||||
archive.unpack(target)?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
Err(Error::UnsupportedArchive(source.as_ref().to_path_buf()))
|
||||
}
|
||||
|
||||
/// Extract the top-level directory from an unpacked archive.
|
||||
///
|
||||
/// The specification says:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue