File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
src/pip/_internal/operations/install Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments