-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
gh-117151: IO performance improvement, increase io.DEFAULT_BUFFER_SIZE to 128k #118144
base: main
Are you sure you want to change the base?
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
@serhiy-storchaka hello, you were kind to review my first PR for buffering performance (118037), would you be able to review this PR too? |
@morotti You still need to write a news entry for the PR. For your other PR this is was not required, but due to the performance impact of this PR I think we should. The most convenient way for this is to click on the The CLA is not yet working, but it worked for the other PR (which was created after this one), so maybe it will resolve itself automatically in a couple of days |
Pinging @benjaminp as expert on io. Could you review this PR? Are there other benchmarks (besides the one in the corresponding issue) we can perform to test this PR? |
Thank you for reviewing, The CLA check is green now and I added a news entry. |
@eendebakpt @benjaminp could you review? |
@morotti The PR looks good from my side, but I am no core dev so I cannot approve. Currently many core devs are at pycon US, so I think we should wait a bit more. If in a few weeks there has been no further response, we can post a message to discourse (see https://devguide.python.org/getting-started/pull-request-lifecycle/#reviewing). |
Requesting Serhiy's review, since he reviewd the other linked (and merged) PR #118037. |
Misc/NEWS.d/next/Core and Builtins/2024-04-30-14-03-09.gh-issue-117151.yt2H8c.rst
Outdated
Show resolved
Hide resolved
Misc/NEWS.d/next/Core and Builtins/2024-04-30-14-03-09.gh-issue-117151.yt2H8c.rst
Outdated
Show resolved
Hide resolved
Misc/NEWS.d/next/Core and Builtins/2024-04-30-14-03-09.gh-issue-117151.yt2H8c.rst
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was convinced that such a change could be beneficial.
But for the case if it has unexpected effect, please ask on https://discuss.python.org/. Update also the C implementation of open()
which is used by default.
Misc/NEWS.d/next/Core and Builtins/2024-04-30-14-03-09.gh-issue-117151.yt2H8c.rst
Outdated
Show resolved
Hide resolved
Please do not use rebase and force-push. It makes reviewing more difficult. |
apologies, I thought I had to squash the new commits and force push. |
all adjusted
|
|
thanks, having a look, looking at the old threads, the bug with winconsole destroying large input was reported in 2010.
|
I've adjusted winconsole to have a different default buffer size. for the impact on read(), it's quite variable.
HOWEVER, that's just for the I/O. the app will do something with the chunks and any python code that is doing not-so-small operation on each chunk can get a very large impact. we've found the bug in pip twice, pypa/pip#12810 the download code is obliterated by the small chunks. it's calling some code and updating a progress bar with each chunk, as much as 30% of the pip runtime is updating the progress bar when it's downloading packages 🫨. it's worthwhile to note that I've found python 3.11 to be 4 times faster than previous versions in tight loop and list comprehension. older python versions would get much more impact from small chunks, due to the larger overhead of many more loop iterations and function calls. |
Soungs good to me. re: Windows, I dug into the docs and history a bit and it looks like with Windows 8+ it's not necessary anymore. I'm seeing if it's possible to remove the special case in gh-121940. |
Misc/NEWS.d/next/Library/2024-04-30-14-03-09.gh-issue-117151.yt2H8c.rst
Outdated
Show resolved
Hide resolved
…ER_SIZE to 128k, adjust open() to use max(st_blksize, io.DEFAULT_BUFFER_SIZE)
e2f33ef
to
c49b15a
Compare
@@ -1558,15 +1559,18 @@ def __init__(self, file, mode='r', closefd=True, opener=None): | |||
os.set_inheritable(fd, False) | |||
|
|||
self._closefd = closefd | |||
self._stat_atopen = os.fstat(fd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to merge changes with #123412 (the stat result is now stashed as a member so can do a number of optimizations with it)
See discussion gh-117151
This patch adjusts the buffer size. That gives 3 to 5 times I/O performance improvement on modern hardware.