Without output.getvalue() the StringIO object will just accumulate references to s until it hits 100,000 references, at which point the internal buffer will actually be realized.
Currently, this benchmark can be run and do 99,999 .write() operations on the StringIO object but 99_999 * CHUNK_SIZE bytes are not written into memory as a single 99GB buffer.
Without
output.getvalue()
the StringIO object will just accumulate references tos
until it hits 100,000 references, at which point the internal buffer will actually be realized.Currently, this benchmark can be run and do 99,999
.write()
operations on theStringIO
object but99_999 * CHUNK_SIZE
bytes are not written into memory as a single 99GB buffer.