You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use PyBytesWriter API in io.RawIOBase.readall #140135
This has definitely shown up in user profiles although most the time FileIO.readall (which is an implementation of RawIOBase.readall) ends up getting called
I like this as an optimization although to me is an intermediate state. I really want to update this to use bytearray + readinto + take_bytes() which does the same thing with less allocations + copies (self.read() allocates and returns a new bytes which is copied into the PyBytesWriter here). I don't think that should block this optimization though. Changing io.RawIOBase to defaulting to .readinto from .read is unfortunately complicated to do without breaking compatibility or making infinite loops.
Activity
[-]Use PyBytesWriter API in `io.RawIOBase.readall`[/-][+]Use `PyBytesWriter` API in `io.RawIOBase.readall`[/+]cmaloney commentedon Oct 14, 2025
cc: @vstinner, @emmatyping . This a very similar optimization to gh-139877.
This has definitely shown up in user profiles although most the time
FileIO.readall(which is an implementation ofRawIOBase.readall) ends up getting calledI like this as an optimization although to me is an intermediate state. I really want to update this to use
bytearray+readinto+take_bytes()which does the same thing with less allocations + copies (self.read()allocates and returns a newbyteswhich is copied into thePyBytesWriterhere). I don't think that should block this optimization though. Changingio.RawIOBaseto defaulting to.readintofrom.readis unfortunately complicated to do without breaking compatibility or making infinite loops.gh-140135: Use `PyBytesWriter` in `io.RawIOBase.readall()`; 4x faster (…
pythongh-140135: Use `PyBytesWriter` in `io.RawIOBase.readall()`; 4x …