Skip to content

Commit 67ef1c2

Browse files
committed
Doc: Clarify that shutil.copyfile() does not use CopyFile2 on Windows
1 parent 96e4cd6 commit 67ef1c2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Doc/library/shutil.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,17 @@ On Linux :func:`os.copy_file_range` or :func:`os.sendfile` is used.
538538

539539
On Solaris :func:`os.sendfile` is used.
540540

541-
On Windows :func:`shutil.copyfile` uses a bigger default buffer size (1 MiB
542-
instead of 64 KiB) and a :func:`memoryview`-based variant of
543-
:func:`shutil.copyfileobj` is used.
541+
On Windows, :func:`shutil.copy`, :func:`shutil.copy2`, :func:`shutil.copytree`,
542+
and :func:`shutil.move` use the native ``CopyFile2`` API (available on Windows 8
543+
and later) when possible. This performs the copy entirely in kernel space,
544+
supports copy-on-write, and avoids copying data through userspace buffers,
545+
resulting in significantly better performance—especially for large files or
546+
files on network shares.
547+
548+
In contrast, :func:`shutil.copyfile` does **not** use ``CopyFile2``; it still
549+
performs a userspace read/write loop (albeit with a larger 1 MiB buffer since
550+
Python 3.8). Therefore, for best performance on Windows, prefer :func:`copy2`
551+
over :func:`copyfile` when preserving metadata (like timestamps) is acceptable.
544552

545553
If the fast-copy operation fails and no data was written in the destination
546554
file then shutil will silently fallback on using less efficient

0 commit comments

Comments
 (0)