[commit: packages/directory] master: Reduce system call overhead of `copyFile` by increasing the buffer size to 128 KiB. (51a0f72)

git at git.haskell.org git at git.haskell.org
Mon Apr 17 21:35:16 UTC 2017


Repository : ssh://git@git.haskell.org/directory

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/51a0f72dc2dbed33d9ce47d9d5073973cd9a0d2a/directory

>---------------------------------------------------------------

commit 51a0f72dc2dbed33d9ce47d9d5073973cd9a0d2a
Author: Niklas Hambüchen <mail at nh2.me>
Date:   Wed Feb 8 04:03:27 2017 +0100

    Reduce system call overhead of `copyFile` by increasing the buffer size to 128 KiB.
    
    128 KiB is what coreutils `cp` uses, based on a benchmark provided here:
    http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/ioblksize.h?id=c0a79542fb5c2c22cf0a250db94af6f8581ca342#n23
    
    The benchmarks report speedups of factor 5x to 30x depending on
    the hardware.


>---------------------------------------------------------------

51a0f72dc2dbed33d9ce47d9d5073973cd9a0d2a
 System/Directory.hs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/System/Directory.hs b/System/Directory.hs
index be98632..7829ecf 100644
--- a/System/Directory.hs
+++ b/System/Directory.hs
@@ -896,7 +896,7 @@ copyHandleData hFrom hTo =
   (`ioeAddLocation` "copyData") `modifyIOError` do
     allocaBytes bufferSize go
   where
-    bufferSize = 1024
+    bufferSize = 131072 -- 128 KiB, as coreutils `cp` uses as of May 2014 (see ioblksize.h)
     go buffer = do
       count <- hGetBuf hFrom buffer bufferSize
       when (count > 0) $ do



More information about the ghc-commits mailing list