Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-117151: IO performance improvement, increase io.DEFAULT_BUFFER_SIZE to 128k#118144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
1d85458da988baeaa0df61af8e1818f472cd7e0cf707be8af8546600a1df21d4e0e1e10ab4592209706e7ce54c44e9b68d421ec33f7ecbef54bc5eef9258be3a78177File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -23,8 +23,9 @@ | ||
| 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(min(blocksize, 8 MiB), DEFAULT_BUFFER_SIZE) | ||
| # when the device block size 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 | ||
| @@ -123,10 +124,10 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None, | ||
| the size of a fixed-size chunk buffer. When no buffering argument is | ||
| given, the default buffering policy works as follows: | ||
| * Binary files are buffered in fixed-size chunks; the size of the buffer | ||
| is chosen using a heuristic trying to determine the underlying device's | ||
| "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`. | ||
| On many systems, the buffer will typically be 4096 or 8192 bytes long. | ||
| * Binary files are buffered in fixed-size chunks; the size of the buffer | ||
| is max(min(blocksize, 8 MiB), DEFAULT_BUFFER_SIZE) | ||
| when the device block size is available. | ||
| On most systems, the buffer will typically be 128 kilobytes long. | ||
| * "Interactive" text files (files for which isatty() returns True) | ||
| use line buffering. Other text files use the policy described above | ||
| @@ -242,7 +243,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None, | ||
| buffering = -1 | ||
| line_buffering = True | ||
| if buffering < 0: | ||
| buffering = raw._blksize | ||
morotti marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| buffering = max(min(raw._blksize, 8192 * 1024), DEFAULT_BUFFER_SIZE) | ||
| if buffering < 0: | ||
| raise ValueError("invalid buffering size") | ||
| if buffering == 0: | ||
morotti marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Increase ``io.DEFAULT_BUFFER_SIZE`` from 8k to 128k and adjust :func:`open` on | ||
| platforms where :meth:`os.fstat` provides a ``st_blksize`` field (such as Linux) | ||
| to use ``max(min(blocksize, 8 MiB), io.DEFAULT_BUFFER_SIZE)`` rather | ||
| than always using the device block size. This should improve I/O performance. | ||
| Patch by Romain Morotti. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.