Skip to content

Commit 6efd95c

Browse files
morottirmmancom
andauthored
gh-117151: increase default buffer size of shutil.copyfileobj() to 256k. (GH-119783)
* gh-117151: increase default buffer size of shutil.copyfileobj() to 256k. it was set to 16k in the 1990s. it was raised to 64k in 2019. the discussion at the time mentioned another 5% improvement by raising to 128k and settled for a very conservative setting. it's 2024 now, I think it should be revisited to match modern hardware. I am measuring 0-15% performance improvement when raising to 256k on various types of disk. there is no downside as far as I can tell. this function is only intended for sequential copy of full files (or file like objects). it's the typical use case that benefits from larger operations. for reference, I came across this function while trying to profile pip that is using it to copy files when installing python packages. * add news --------- Co-authored-by: rmorotti <[email protected]>
1 parent 8bcf118 commit 6efd95c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Lib/shutil.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
else:
4545
_winapi = None
4646

47-
COPY_BUFSIZE = 1024 * 1024 if _WINDOWS else 64 * 1024
47+
COPY_BUFSIZE = 1024 * 1024 if _WINDOWS else 256 * 1024
4848
# This should never be removed, see rationale in:
4949
# https://bugs.python.org/issue43743#msg393429
5050
_USE_CP_SENDFILE = (hasattr(os, "sendfile")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The default buffer size used by :func:`shutil.copyfileobj` has been
2+
increased from 64k to 256k on non-Windows platforms. It was already larger
3+
on Windows.

0 commit comments

Comments
 (0)