Commit 14856043 authored by simonmar's avatar simonmar
Browse files

[project @ 2001-09-17 16:21:41 by simonmar]

Subvert GHC's full-laziness optimisation by explicitly lambda-lifting
a local lambda expression to the top level, and exporting it to ensure
it doesn't get inlined.  Without this hack, full-laziness will float
out several subexpressions, which turns out to be a pessimisation in
this case.

This is worth about 20% in hPutStr performance, so we now beat the old
I/O library on 'cat' ;-)

I'd like to MERGE TO STABLE this, but 5.02 is imminent so it might
have to wait until 5.02.1.
parent a3b0f2a6
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#undef DEBUG_DUMP #undef DEBUG_DUMP
-- ----------------------------------------------------------------------------- -- -----------------------------------------------------------------------------
-- $Id: PrelIO.hsc,v 1.13 2001/09/17 14:58:09 simonmar Exp $ -- $Id: PrelIO.hsc,v 1.14 2001/09/17 16:21:41 simonmar Exp $
-- --
-- (c) The University of Glasgow, 1992-2001 -- (c) The University of Glasgow, 1992-2001
-- --
...@@ -18,7 +18,8 @@ module PrelIO ( ...@@ -18,7 +18,8 @@ module PrelIO (
putChar, putStr, putStrLn, print, getChar, getLine, getContents, putChar, putStr, putStrLn, print, getChar, getLine, getContents,
interact, readFile, writeFile, appendFile, readLn, readIO, hReady, interact, readFile, writeFile, appendFile, readLn, readIO, hReady,
hWaitForInput, hGetChar, hGetLine, hGetContents, hPutChar, hPutStr, hWaitForInput, hGetChar, hGetLine, hGetContents, hPutChar, hPutStr,
hPutStrLn, hPrint hPutStrLn, hPrint,
commitBuffer, commitBuffer'
) where ) where
#include "HsStd.h" #include "HsStd.h"
...@@ -553,13 +554,25 @@ commitBuffer ...@@ -553,13 +554,25 @@ commitBuffer
:: Handle -- handle to commit to :: Handle -- handle to commit to
-> RawBuffer -> Int -- address and size (in bytes) of buffer -> RawBuffer -> Int -- address and size (in bytes) of buffer
-> Int -- number of bytes of data in buffer -> Int -- number of bytes of data in buffer
-> Bool -- flush the handle afterward? -> Bool -- True <=> flush the handle afterward
-> Bool -- release the buffer? -> Bool -- release the buffer?
-> IO Buffer -> IO Buffer
commitBuffer hdl raw sz count flush release = do commitBuffer hdl raw sz@(I## _) count@(I## _) flush release = do
wantWritableHandle "commitAndReleaseBuffer" hdl $ wantWritableHandle "commitAndReleaseBuffer" hdl $
\ handle_@Handle__{ haFD=fd, haBuffer=ref, haBuffers=spare_buf_ref } -> do commitBuffer' hdl raw sz count flush release
-- Explicitly lambda-lift this function to subvert GHC's full laziness
-- optimisations, which otherwise tends to float out subexpressions
-- past the \handle, which is really a pessimisation in this case because
-- that lambda is a one-shot lambda.
--
-- Don't forget to export the function, to stop it being inlined too.
--
-- This hack is a fairly big win for hPutStr performance.
--
commitBuffer' hdl raw sz@(I## _) count@(I## _) flush release
handle_@Handle__{ haFD=fd, haBuffer=ref, haBuffers=spare_buf_ref } = do
#ifdef DEBUG_DUMP #ifdef DEBUG_DUMP
puts ("commitBuffer: sz=" ++ show sz ++ ", count=" ++ show count puts ("commitBuffer: sz=" ++ show sz ++ ", count=" ++ show count
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment