Skip to content

Commit

Permalink
Merge pull request #12803 from man-group/perf-optimize-extraction
Browse files Browse the repository at this point in the history
PERF: extract files from wheel in 1MB blocks + skip decoding for 0 bytes files
  • Loading branch information
pfmoore authored Jul 17, 2024
2 parents ee63643 + 52cb382 commit 7ec5fc3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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 @@ -371,9 +371,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

0 comments on commit 7ec5fc3

Please sign in to comment.