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

bpo-33671 / shutil.copyfile: use memoryview() with dynamic size on Windows#7681

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
giampaolo merged 16 commits intopython:masterfromgiampaolo:33671-release-memoryview
Jun 19, 2018
Merged

bpo-33671 / shutil.copyfile: use memoryview() with dynamic size on Windows#7681

giampaolo merged 16 commits intopython:masterfromgiampaolo:33671-release-memoryview
Jun 19, 2018

Conversation

@giampaolo
Copy link
Contributor

@giampaologiampaolo commentedJun 13, 2018
edited
Loading

This is a follow up of#7160.
Changes:

https://bugs.python.org/issue33671

...as it's considerably slower for smaller files; e.g. with a 8MiB file:--- original~/svn/cpython {33671-release-memoryview}$ ./python  -m timeit -s "importshutil; f1 = open('f1', 'rb'); f2 = open('f2', 'wb')""shutil.copyfileobj(f1, f2)"200000 loops, best of 5: 1.64 usec per loop--- _copybinfileobj()~/svn/cpython {33671-release-memoryview}$ ./python  -m timeit -s "importshutil; f1 = open('f1', 'rb'); f2 = open('f2', 'wb')""shutil.copyfileobj(f1, f2)"100000 loops, best of 5: 3.3 usec per loop
@giampaologiampaolo changed the titlebpo-33671 remove memoryview() from shutil.copyfileobj()bpo-33671 use memoryview()-based variant of copyfileobj() on Win for files >= 128 MiBJun 13, 2018
Lib/shutil.py Outdated

if _HAS_FCOPYFILE:
# macOS
elif _HAS_FCOPYFILE:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Both options are always exclusive? macOS might have sendfile() in the future, no?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is now outdated: I updated code to always use fcopyfile on OSX and leave sendfile() alone. This way we avoid invoking sendfile() on OSX which would fail anyway.

Lib/shutil.py Outdated
# considerable speedup by using a readinto()/memoryview()
# variant of copyfileobj(), see:
# https://github.com/python/cpython/pull/7160#discussion_r195162475
elif _WINDOWS and file_size >= 128 * 1024 * 1024:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Would you mind to add a top-level private constant rather than an hardcoded value? (Would it make sense to make it somehow public? Or add an optional parameter...?)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is outdated, I modified code to always use the readinto() variant regardless of file size, see:#7160 (comment)

As per#7160 (comment)it appears using memoryview() on Windows is faster also for small filesif memoryview() length is equal to file size.
@giampaologiampaolo changed the titlebpo-33671 use memoryview()-based variant of copyfileobj() on Win for files >= 128 MiBbpo-33671 / shutil.copyfile: use memoryview() with dynamic size on WindowsJun 14, 2018
@giampaologiampaolo merged commitc7f02a9 intopython:masterJun 19, 2018
@bedevere-bot
Copy link

@giampaolo: Please replace# withGH- in the commit message next time. Thanks!

@giampaologiampaolo deleted the 33671-release-memoryview branchJune 19, 2018 15:27
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@vstinnervstinnervstinner left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@giampaolo@bedevere-bot@vstinner@the-knights-who-say-ni

[8]ページ先頭

©2009-2026 Movatter.jp