Skip to content

Stream package extraction to bound peak memory usage - #410

Open
joaogabriel15 wants to merge 1 commit into
python:mainfrom
joaogabriel15:fix/stream-package-extraction
Open

Stream package extraction to bound peak memory usage#410
joaogabriel15 wants to merge 1 commit into
python:mainfrom
joaogabriel15:fix/stream-package-extraction

Conversation

@joaogabriel15

Copy link
Copy Markdown

Fixes #409.

Extract ZIP members in 1 MiB chunks instead of materializing each uncompressed member in memory. Destination validation, repair behavior, overwrite warnings, and progress reporting are unchanged.

Adds regression coverage for ZIP and NuGet archives, multi-chunk files, empty files, existing files, and repair. The four new cases fail against the original extraction function and pass with the change.

Validation on Windows, CPython 3.14.3:

  • Installation tests: 28 passed.
  • Full suite: 433 passed, 28 failed. The same 28 verification/download tests also fail with the original extraction function in this environment.
  • Synthetic 64 MiB deflated member: tracemalloc peak decreased from 141.74 MiB to 3.42 MiB. This measures Python allocations, not process RSS or real-package installation throughput.

@python-cla-bot

python-cla-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

with open(dest, "wb") as f:
f.write(zf.read(member))
with zf.open(member) as source, open(dest, "wb") as f:
shutil.copyfileobj(source, f, length=1024 * 1024)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How badly does it affect the maximum memory usage if we make this use 10MB instead of 1MB? I'd like our standard Python distributions to still only use one call per file, and the biggest file we include is (currently) around 7MB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce peak memory usage during package extraction

2 participants