Skip to content

Commit e9b2714

Browse files
committed
pythongh-117151: IO performance improvement, increase io.DEFAULT_BUFFER_SIZE to 128k, fix open() to use max(st_blksize, io.DEFAULT_BUFFER_SIZE)
performance:
1 parent 9654daf commit e9b2714

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Lib/_pyio.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
valid_seek_flags.add(os.SEEK_HOLE)
2424
valid_seek_flags.add(os.SEEK_DATA)
2525

26-
# open() uses st_blksize whenever we can
27-
DEFAULT_BUFFER_SIZE = 8 * 1024 # bytes
26+
# open() uses max(st_blksize, io.DEFAULT_BUFFER_SIZE) when st_blksize is available
27+
DEFAULT_BUFFER_SIZE = 128 * 1024 # bytes
2828

2929
# NOTE: Base classes defined here are registered with the "official" ABCs
3030
# defined in io.py. We don't use real inheritance though, because we don't want
@@ -249,7 +249,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
249249
pass
250250
else:
251251
if bs > 1:
252-
buffering = bs
252+
buffering = max(bs, DEFAULT_BUFFER_SIZE)
253253
if buffering < 0:
254254
raise ValueError("invalid buffering size")
255255
if buffering == 0:

0 commit comments

Comments
 (0)