You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use high-performance os.sendfile() in shutil.copy* #77820
This is a follow up of bpo-25063 and similar to socket.sendfile() (bpo-17552). It provides a 20/25% speedup when copying files with shutil.copyfile(), shutil.copy() and shutil.copy2(). Differently from bpo-25063 this is used for filesystem files only and copyfileobj() is left alone.
Unmerged bpo-26826 is also related to this. I applied bpo-26826 patch and built a wrapper around copy_file_range() and the speedup is basically the same. Nevertheless, even when bpo-26826 gets merged it probably makes sense to rely on sendfile() in case copy_file_range() is not available (it was introduced in 2016) or the UNIX platform supports file-to-file copy via sendfile(2) (even though I'm not aware of any, so this would basically be Linux-only).
Oh! I got confused by the fact that bpo-25063 was rejected due to concerns about copyfileobj() otherwise I would have commented on your patch which I totally missed. Yes, this overlaps with bpo-25156 patch but it uses the same logic of socket.sendfile() which IMO is more robust. If you agree I'd close bpo-25156 and continue in here, and I'm more than happy to co-author the contribution if that's OK with you.
desbma commented on May 24, 2018
desbmamannequin
Mannequin
More actions
Honestly, whatever gets this thing moving forward is good with me.
I'm a bit depressed by the number of issues here that have a good patch waiting to be merged, or even read, and that languish for years.
I haven't read your patch in detail, but if others agree that it is better than mine and can be merged, let's do it.
I'm a bit depressed by the number of issues here that have a good patch waiting to be merged, or even read, and that languish for years.
I'm really sorry about that. We, core developers, are doing our best, but we are 34 active core developers who merged 5000 pull requests in 1 year. We don't scale well :-(
I updated the code to rely on sendfile(2) on Linux only, which apparently is the only one supporting copy between regular files and added a check to fail immediately in case the filesystem is full.
Activity
giampaolo commentedon May 24, 2018
This is a follow up of bpo-25063 and similar to socket.sendfile() (bpo-17552). It provides a 20/25% speedup when copying files with shutil.copyfile(), shutil.copy() and shutil.copy2(). Differently from bpo-25063 this is used for filesystem files only and copyfileobj() is left alone.
Unmerged bpo-26826 is also related to this. I applied bpo-26826 patch and built a wrapper around copy_file_range() and the speedup is basically the same. Nevertheless, even when bpo-26826 gets merged it probably makes sense to rely on sendfile() in case copy_file_range() is not available (it was introduced in 2016) or the UNIX platform supports file-to-file copy via sendfile(2) (even though I'm not aware of any, so this would basically be Linux-only).
Some benchmarks:
$ dd if=/dev/urandom of=/tmp/f1 bs=1K count=128 $ time ./python -m timeit -s 'import shutil; p1 = "/tmp/f1"; p2 = "/tmp/f2"' 'shutil.copyfile(p1, p2)'128K copy
=========
--- without patch:
--- with patch:
8MB copy
========
--- without patch:
--- with patch:
512MB copy
==========
--- without patch:
--- with patch:
desbma commentedon May 24, 2018
Duplicate of https://bugs.python.org/issue25156 ?
giampaolo commentedon May 24, 2018
Oh! I got confused by the fact that bpo-25063 was rejected due to concerns about copyfileobj() otherwise I would have commented on your patch which I totally missed. Yes, this overlaps with bpo-25156 patch but it uses the same logic of socket.sendfile() which IMO is more robust. If you agree I'd close bpo-25156 and continue in here, and I'm more than happy to co-author the contribution if that's OK with you.
desbma commentedon May 24, 2018
Honestly, whatever gets this thing moving forward is good with me.
I'm a bit depressed by the number of issues here that have a good patch waiting to be merged, or even read, and that languish for years.
I haven't read your patch in detail, but if others agree that it is better than mine and can be merged, let's do it.
vstinner commentedon May 24, 2018
I'm really sorry about that. We, core developers, are doing our best, but we are 34 active core developers who merged 5000 pull requests in 1 year. We don't scale well :-(
We are working on getting more people onboard.
giampaolo commentedon May 26, 2018
I updated the code to rely on sendfile(2) on Linux only, which apparently is the only one supporting copy between regular files and added a check to fail immediately in case the filesystem is full.
Can somebody review the patch?
giampaolo commentedon May 28, 2018
Closing as duplicate of bpo-33671.
giampaolo commentedon May 28, 2018
Closing as duplicate of bpo-33671.