Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions news/12803.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Improve pip install performance. Files are now extracted in 1MB blocks,
or in one block matching the file size for smaller files.
A decompressor is no longer instantiated when extracting 0 bytes files,
it is not necessary because there is no data to decompress.
10 changes: 7 additions & 3 deletions src/pip/_internal/operations/install/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,13 @@ def save(self) -> None:

zipinfo = self._getinfo()

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

if zip_item_is_executable(zipinfo):
set_extracted_file_to_default_mode_plus_executable(self.dest_path)
Expand Down