Repository navigation
perf: send upload bodies in 1 MiB blocks instead of 16 KiB - #670
Open
patrick-immometrica wants to merge 1 commit into
Open
patrick-immometrica wants to merge 1 commit into
patrick-immometrica wants to merge 1 commit into
Conversation
urllib3 reads file-like bodies in 16 KiB chunks by default, so each upload part went through StreamWithHash and the progress wrapper thousands of times, with the GIL held.
patrick-immometrica
marked this pull request as ready for review
November 15, 2026 14:24
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NotDecompressingHTTPAdapterdoesn't setblocksize, so urllib3 uses its 16 KiB default and reads upload bodies 16 KiB at a time. A 100 MB part means ~6400 reads throughReadingStreamWithProgress->StreamWithHash-> socket, all in Python with the GIL held, which hurts most when several upload threads run at once.This sets it to 1 MiB for the pool manager and for proxy managers.
Rough numbers from a local sink over loopback HTTP, 64 MiB bodies through the real stream wrappers:
On a slow link the network still dominates, but the CPU per uploaded byte drops either way. Progress callbacks now come in up to 1 MiB steps instead of 16 KiB.