Repository navigation
Conversation
…block Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
While the patch is correct, we don't want fully automated PRs opened automatically. So please avoid opening further PRs until they are merged. In particular, I would advise that you first trim down the description by yourself without ANY agent behind. |
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.
Summary
_Stream.__writewrites one block and then slices it off the front ofbuf, which copies everything left. For a chunk ofcbytes that's about c²/(2·bufsize) bytes copied. At the default 16 KiB copy buffer you can't see it. Setcopybufsizeto a few MiB and a bigger buffer makesw|writes slower.Now it writes each whole block straight from
buf, then keeps the remainder:endis picked so the same 1..bufsize bytes stay behind as before. The file object gets the samebytesblocks, in the same order.Evidence
One 64 MiB member written with
mode='w|'toBytesIO, then read back and checked. 3.16 dev build, macOS arm64, median of 3, two alternating runs:I can't count slice copies from a test, so the new test
test_stream_write_large_chunksguards behaviour instead: withcopybufsizeset to a 256 KiB member, everywrite()the file object sees isbytesand exactlyRECORDSIZElong, and the archive reads back the same.I also ran old and new
_Streamagainst each other on 1,200 random chunk sequences, using tar, gz, bz2 and xz with bufsize 1, 7, 512 and 10240. The list ofwrite()calls was identical every time.test_tarfile+test_shutil: 1,016 run, all pass.Merge Danger
Door: two-way
Same output, same write calls. Only the internal buffer handling changes.
Blast Radius: stdlib
Any
tarfilestream write (w|,w|gz, and so on) goes through this code. Custom file objects still getbytesblocks of the same size.AI disclosure: the profiling, the patch and the equivalence check were done with AI tools (Codex, Claude).
🤖 Generated with Claude Code