Skip to content

Commit 7ec5fc3

Browse files
authored
Merge pull request #12803 from man-group/perf-optimize-extraction
PERF: extract files from wheel in 1MB blocks + skip decoding for 0 bytes files
2 parents ee63643 + 52cb382 commit 7ec5fc3

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

news/12803.bugfix.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Improve pip install performance. Files are now extracted in 1MB blocks,
2+
or in one block matching the file size for smaller files.
3+
A decompressor is no longer instantiated when extracting 0 bytes files,
4+
it is not necessary because there is no data to decompress.

src/pip/_internal/operations/install/wheel.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,13 @@ def save(self) -> None:
371371

372372
zipinfo = self._getinfo()
373373

374-
with self._zip_file.open(zipinfo) as f:
375-
with open(self.dest_path, "wb") as dest:
376-
shutil.copyfileobj(f, dest)
374+
# optimization: the file is created by open(),
375+
# skip the decompression when there is 0 bytes to decompress.
376+
with open(self.dest_path, "wb") as dest:
377+
if zipinfo.file_size > 0:
378+
with self._zip_file.open(zipinfo) as f:
379+
blocksize = min(zipinfo.file_size, 1024 * 1024)
380+
shutil.copyfileobj(f, dest, blocksize)
377381

378382
if zip_item_is_executable(zipinfo):
379383
set_extracted_file_to_default_mode_plus_executable(self.dest_path)

0 commit comments

Comments
 (0)