Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff2e3ce

Browse files
committed
gh-117151: IO performance improvement, increase io.DEFAULT_BUFFER_SIZE to 128k, fix open() to use max(st_blksize, io.DEFAULT_BUFFER_SIZE)
1 parent42351c3 commitff2e3ce

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

‎Lib/_pyio.py‎

Lines changed: 3 additions & 3 deletions
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() usesmax(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
ifbs>1:
252-
buffering=bs
252+
buffering=max(bs,DEFAULT_BUFFER_SIZE)
253253
ifbuffering<0:
254254
raiseValueError("invalid buffering size")
255255
ifbuffering==0:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
increase io.DEFAULT_BUFFER_SIZE from 4k/8k to 128k. fix open on Linux to use
2+
max(io.DEFAULT_BUFFER_SIZE, device block size) rather than the device block
3+
size. improve I/O performance by 3 to 5 times. patch by Romain Morotti.

‎Modules/_io/_iomodule.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ extern Py_ssize_t _PyIO_find_line_ending(
7878
*/
7979
externint_PyIO_trap_eintr(void);
8080

81-
#defineDEFAULT_BUFFER_SIZE (8 * 1024)/* bytes */
81+
#defineDEFAULT_BUFFER_SIZE (128 * 1024)/* bytes */
8282

8383
/*
8484
* Offset type for positioning.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp