Skip to content

perf: reduce multipart upload memory overlap - #579

Open
perfloop-agent wants to merge 8 commits into
cloudsmith-io:masterfrom
perfloop-oss:perfloop-pr-open-38gn3scm95
Open

perfloop-agent wants to merge 8 commits into
cloudsmith-io:masterfrom
perfloop-oss:perfloop-pr-open-38gn3scm95

Conversation

@perfloop-agent

@perfloop-agent perfloop-agent commented Nov 1, 2026 •

Copy link
Copy Markdown

Description

Large multipart uploads release the prior response and part bytes after each successful PUT, before reading the next part.

At @cloudsmith-iduffy's invitation, this complements PR #544. In cloudsmith_cli/core/api/files.py, #544 changes the same data= line to data=io.BytesIO(chunk) and adds an upload timeout. That replayable in-memory body still contains a whole part. This change keeps the existing request body through retries and redirects, then drops resp and chunk after success. It can be combined with #544's BytesIO and timeout changes; it does not need a file-backed stream or temporary storage.

The 100 MiB part boundaries, serial PUT order, authentication, callbacks, and completion after all parts succeed remain unchanged. Files below the existing multipart threshold keep the single-request path.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring
  • Other (performance improvement)

Additional Notes

cloudsmith_cli/core/tests/test_files.py::TestMultiPartUploadMemory::test_peak_traced_memory_stays_below_two_parts uses benchmarks/bench_multipart_upload.py’s measure_peak_traced_heap for a two-full-parts-plus-one-byte fixture and checks the two-part ceiling. The shared helper retains the request body in a 200 requests.Response and checks completion once.

After uv sync --locked --group dev, run .venv/bin/python -B benchmarks/bench_multipart_upload.py. It reports helper-level traced heap for the same fixture, not the registered CLI or process RSS.

Results

For a 128 MiB push raw with the update check due, median peak traced Python heap fell from 258.4 MB to 153.6 MB (40.53% less heap, 15 complete pairs), measured with a harness not included in this PR. SDK control replies and the update manifest were local fixtures; checksum calculation and HTTP part transfers ran.

benchmarks/bench_multipart_upload.py on a file of two full parts plus one byte (209,715,201 bytes, 104,857,600-byte parts), Python tracemalloc peak:

Before After Change
Peak traced heap 209,725,305 B (two parts) 104,865,960 B (one part) not paired

Production frequency and deployed memory impact remain unknown. Each part is still fully materialized in memory, up to 100 MiB; this change reduces overlap rather than streaming the request body. No process-RSS reduction or upload-speed claim is made.

pytest passed five scoped multipart upload tests on each of Python 3.11–3.14 (no failures or skips).

Registered-push measurement details

The exact medians were 258,360,994 B and 153,638,665 B; paired median change was −104,722,601 B, with sequential bounds −104,723,495 to −104,719,135 B. There were 15 complete pairs.

Case and evidence


Generated by Perfloop. Human sponsor: Tomás Senart.

Copilot AI balanced review requested due to automatic review settings November 1, 2026 23:57
@perfloop-agent
perfloop-agent requested a review from a team as a code owner November 1, 2026 23:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new benchmarks/bench_multipart_upload.py module is missing the copyright notice required by the repository guidelines.

1 open issue
What changed in this PR

Reduces memory overlap during large multipart uploads by releasing each successful response and its part bytes before reading the next part, without changing part sizes or upload order.

Changes:

  • Releases completed multipart request data after each successful PUT.
  • Adds a shared traced-heap benchmark and a regression test for peak memory.
  • Documents the improvement in the changelog.
File Description
cloudsmith_cli/​core/​tests/​test_files.py Adds a regression test enforcing a two-part traced-memory ceiling.
cloudsmith_cli/​core/​api/​files.py Releases the response and chunk before reading the next part.
CHANGELOG.md Notes reduced overlap between consecutive request bodies.
benchmarks/​bench_multipart_upload.py Adds a reusable memory measurement helper and standalone benchmark.

Review effort: Balanced

Comment thread benchmarks/bench_multipart_upload.py Resolved
@tsenart

tsenart commented Nov 2, 2026

Copy link
Copy Markdown

Hi, I'm Tomás, I build Perfloop. I approved this contribution and will handle review feedback here.

@cloudsmith-iduffy, thanks for the invitation. This complements your #544 and should combine cleanly with its BytesIO and timeout changes. We found it while hunting performance improvements with Perfloop. We've had changes merged in Dolt, Prometheus, Skipper, parquet-go, RoaringBitmap, and more.

If you'd like anything in this patch changed, just let me know and I'll update it.

@cloudsmith-iduffy
cloudsmith-iduffy self-requested a review November 2, 2026 07:26
@cloudsmith-iduffy

Copy link
Copy Markdown
Collaborator

Thanks for this @perfloop-agent and @tsenart ! We will get #544 across the line and then look at getting this one merged in.

Thanks for running your tool over the code base and look forward to having a call with you later this month :).

@tsenart

tsenart commented Nov 3, 2026

Copy link
Copy Markdown

Thanks for running your tool over the code base and look forward to having a call with you later this month :).

I look forward to it to!

@perfloop-agent
perfloop-agent force-pushed the perfloop-pr-open-38gn3scm95 branch 2 times, most recently from 5231ce3 to ca32b36 Compare November 16, 2026 03:49
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
@perfloop
perfloop Bot force-pushed the perfloop-pr-open-38gn3scm95 branch from ca32b36 to e6fe9cd Compare December 1, 2026 21:15

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants