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
_io.FileIO uses a quadratic-time buffer growth algorithm #57368
As mentioned in bpo-6715, the buffer growth strategy used by _io.FileIO
has quadratic running time if each reallocation is O(n). The code in
question is new_buffersize() from Modules/_io/fileio.c:
if (currentsize>SMALLCHUNK) {
/* Keep doubling until we reach BIGCHUNK; then keep adding BIGCHUNK. */if (currentsize <= BIGCHUNK)
returncurrentsize+currentsize;
elsereturncurrentsize+BIGCHUNK;
}
returncurrentsize+SMALLCHUNK;
Is there a reason for this? One possible improvement would be to instead
use the same formula as list.resize() in Objects/listobject.c:
Activity
nadeemvawda commentedon Oct 12, 2011
As mentioned in bpo-6715, the buffer growth strategy used by _io.FileIO
has quadratic running time if each reallocation is O(n). The code in
question is new_buffersize() from Modules/_io/fileio.c:
Is there a reason for this? One possible improvement would be to instead
use the same formula as list.resize() in Objects/listobject.c:
which has amortized O(n) running time behaviour.
Your thoughts?
nadeemvawda commentedon Oct 12, 2011
I've attached a patch that makes the suggested change to FileIO, and also
to _bz2.BZ2Compressor/Decompressor (which currently have the same issue).
pitrou commentedon Oct 12, 2011