From: Simon Marlow Date: Tue, 21 Dec 2010 15:51:54 +0000 (+0000) Subject: Always use 8k buffers instead of BUFSIZ X-Git-Url: http://git.megacz.com/?p=ghc-base.git;a=commitdiff_plain;h=9d4854353702fa835ba9a8ed57d4f0d689877d07 Always use 8k buffers instead of BUFSIZ This makes a huge difference to I/O performance for me on Windows, where BUFSIZ is 512. It might help on Mac too. --- diff --git a/GHC/IO/FD.hs b/GHC/IO/FD.hs index 659f610..f2ce275 100644 --- a/GHC/IO/FD.hs +++ b/GHC/IO/FD.hs @@ -99,8 +99,15 @@ instance GHC.IO.Device.IODevice FD where dup = dup dup2 = dup2 +-- We used to use System.Posix.Internals.dEFAULT_BUFFER_SIZE, which is +-- taken from the value of BUFSIZ on the current platform. This value +-- varies too much though: it is 512 on Windows, 1024 on OS X and 8192 +-- on Linux. So let's just use a decent size on every platform: +dEFAULT_FD_BUFFER_SIZE :: Int +dEFAULT_FD_BUFFER_SIZE = 8096 + instance BufferedIO FD where - newBuffer _dev state = newByteBuffer dEFAULT_BUFFER_SIZE state + newBuffer _dev state = newByteBuffer dEFAULT_FD_BUFFER_SIZE state fillReadBuffer fd buf = readBuf' fd buf fillReadBuffer0 fd buf = readBufNonBlocking fd buf flushWriteBuffer fd buf = writeBuf' fd buf diff --git a/GHC/IO/Handle/Internals.hs b/GHC/IO/Handle/Internals.hs index 2aad185..76e8b00 100644 --- a/GHC/IO/Handle/Internals.hs +++ b/GHC/IO/Handle/Internals.hs @@ -390,7 +390,7 @@ handleFinalizer fp m = do -- using an 8k char buffer instead of 32k improved performance for a -- basic "cat" program by ~30% for me. --SDM dEFAULT_CHAR_BUFFER_SIZE :: Int -dEFAULT_CHAR_BUFFER_SIZE = dEFAULT_BUFFER_SIZE `div` 4 +dEFAULT_CHAR_BUFFER_SIZE = 2048 -- 8k/sizeof(HsChar) getCharBuffer :: IODevice dev => dev -> BufferState -> IO (IORef CharBuffer, BufferMode)