Skip to content

gh-141968: Use bytearray.take_bytes() in more I/O paths - #156989

Closed
methane wants to merge 1 commit into
python:mainfrom
methane:optimize-take-bytes-io
Closed

gh-141968: Use bytearray.take_bytes() in more I/O paths#156989
methane wants to merge 1 commit into
python:mainfrom
methane:optimize-take-bytes-io

Conversation

@methane

@methane methane commented Sep 5, 2026

Copy link
Copy Markdown
Member

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-05T15:23:41.568035Z 94ff007 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@methane
methane requested review from cmaloney and a balanced review from Copilot September 5, 2026 15:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Both changes preserve return types and behavior while safely eliminating unnecessary copies from locally owned bytearrays.

Pull request overview

Uses bytearray.take_bytes() to avoid final buffer copies in I/O and ZIP decryption paths.

Changes:

  • Optimizes _IOBase.readline().
  • Optimizes legacy ZIP decryption output.
File summaries
File Description
Modules/_io/iobase.c Transfers the readline buffer directly into bytes.
Lib/zipfile/__init__.py Transfers decrypted output directly into bytes.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@cmaloney cmaloney 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.

👍

I had a PR for the zipfile one previously (#142240). I think it is reasonable to do but hard to benchmark (the decrypter usage is uncommon).

For .readline() it probably makes sense to move entirely to PyBytesWriter (https://peps.python.org/pep-0782/). That is a separate larger scope change though.

@methane
methane force-pushed the optimize-take-bytes-io branch 2 times, most recently from 8de25cb to c4f4c75 Compare September 6, 2026 04:10
@methane methane closed this Sep 6, 2026
@methane
methane deleted the optimize-take-bytes-io branch September 6, 2026 05:41
@methane

methane commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

OK. I used PyBytesWriter in #157024

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants