I had always thought that BytesIO.getvalue() copied all the memory. Turns out I was wrong, and the CPython developers had a trick up their sleeves.
https://pythonspeed.com/articles/bytesio-reduce-memory-usage/
@itamarst Very interesting. I work a lot with Python, and often go exploring in the CPython source.
Small note: 3.10 reaches EOL in 2026, not 2027.
@itamarst Thanks, TIL!