Skip to content

Commit 4dd39e8

Browse files
Use uncompressed editable wheels (#21918)
Editable wheels currently use the normal Deflate writer even though the backend has an uncompressed writer for them. Route `build_editable` through that writer so the temporary wheel entries use Stored compression. Regular wheel compression and the installed file contents are unchanged. Local release benchmarks against the exact parent reduce time in `build_editable` by 7.8% (95% CI 5.8–9.7%) for a minimal package and 6.8% (95% CI 3.5–11.6%) for `built-by-uv`. A same-process comparison and CPU timings support the savings; forced `uv sync` reinstalls did not show a measurable end-to-end improvement. [Detailed benchmarks](astral-sh#1999 (comment)). Co-authored-by: zaniebot <[email protected]>
1 parent 0c8da51 commit 4dd39e8

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎crates/uv-build-backend/src/lib.rs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ pub(crate) fn error_on_venv(file_name: &OsStr, path: &Path) -> Result<(), Error>
479479
#[cfg(test)]
480480
mod tests {
481481
use super::*;
482+
use async_zip::Compression;
482483
use async_zip::base::read::mem::ZipFileReader;
483484
use flate2::bufread::GzDecoder;
484485
use fs_err::File;
@@ -719,6 +720,34 @@ mod tests {
719720
);
720721
}
721722

723+
#[test]
724+
fn editable_wheel_compression() -> Result<(), Error> {
725+
let _preview = uv_preview::test::with_features(&[]);
726+
let source = Path::new("../../test/packages/built-by-uv");
727+
let dist = TempDir::new()?;
728+
729+
let filename = build_wheel(source, dist.path(), None, MOCK_UV_VERSION, false)?;
730+
let wheel = block_on(read_wheel(&dist.path().join(filename.to_string())));
731+
let filename = build_editable(source, dist.path(), None, MOCK_UV_VERSION, false)?;
732+
let editable = block_on(read_wheel(&dist.path().join(filename.to_string())));
733+
734+
for (archive, compression) in [
735+
(wheel, Compression::Deflate),
736+
(editable, Compression::Stored),
737+
] {
738+
assert!(!archive.file().entries().is_empty());
739+
for entry in archive.file().entries() {
740+
let expected = if entry.dir()? {
741+
Compression::Stored
742+
} else {
743+
compression
744+
};
745+
assert_eq!(entry.compression(), expected);
746+
}
747+
}
748+
Ok(())
749+
}
750+
722751
#[test]
723752
fn built_by_uv_building_tar_codec() {
724753
built_by_uv_building_with_backend(

‎crates/uv-build-backend/src/wheel.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ pub fn build_editable(
286286
}
287287

288288
let temp_file = uv_fs::tempfile_in(wheel_dir)?;
289-
let mut wheel_writer = ZipDirectoryWriter::new_wheel(temp_file.as_file());
289+
let mut wheel_writer = ZipDirectoryWriter::new_editable(temp_file.as_file());
290290

291291
debug!("Adding pth file to {}", wheel_path.user_display());
292292
// Check that a module root exists in the directory we're linking from the `.pth` file
@@ -844,7 +844,6 @@ impl<W: Write + Seek + Unpin> ZipDirectoryWriter<SyncWriter<W>> {
844844
/// A wheel writer with no (stored) compression.
845845
///
846846
/// Since editables are temporary, we save time be skipping compression and decompression.
847-
#[expect(dead_code)]
848847
fn new_editable(writer: W) -> Self {
849848
Self {
850849
writer: ZipFileWriter::new(SyncWriter::new(writer)),

0 commit comments

Comments
 (0)