Skip to content

Commit

Permalink
gh-117151: IO performance improvement, increase io.DEFAULT_BUFFER_SIZ…
Browse files Browse the repository at this point in the history
…E to 128k, fix open() to use max(st_blksize, io.DEFAULT_BUFFER_SIZE)
  • Loading branch information
rmmancom committed Apr 30, 2024
1 parent 287d939 commit 3668d1a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
valid_seek_flags.add(os.SEEK_HOLE)
valid_seek_flags.add(os.SEEK_DATA)

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

# NOTE: Base classes defined here are registered with the "official" ABCs
# defined in io.py. We don't use real inheritance though, because we don't want
Expand Down Expand Up @@ -249,7 +249,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
pass
else:
if bs > 1:
buffering = bs
buffering = max(bs, DEFAULT_BUFFER_SIZE)
if buffering < 0:
raise ValueError("invalid buffering size")
if buffering == 0:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
increase io.DEFAULT_BUFFER_SIZE from 4k/8k to 128k. fix open on Linux to use
max(io.DEFAULT_BUFFER_SIZE, device block size) rather than the device block
size. improve I/O performance by 3 to 5 times. patch by Romain Morotti.
2 changes: 1 addition & 1 deletion Modules/_io/_iomodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extern Py_ssize_t _PyIO_find_line_ending(
*/
extern int _PyIO_trap_eintr(void);

#define DEFAULT_BUFFER_SIZE (8 * 1024) /* bytes */
#define DEFAULT_BUFFER_SIZE (128 * 1024) /* bytes */

/*
* Offset type for positioning.
Expand Down

0 comments on commit 3668d1a

Please sign in to comment.