[GHC] #9520: Running an action twice uses much more memory than running it once
GHC
ghc-devs at haskell.org
Thu Aug 28 14:27:31 UTC 2014
#9520: Running an action twice uses much more memory than running it once
-------------------------------------+-------------------------------------
Reporter: snoyberg | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.3
Resolution: | Keywords:
Operating System: Linux | Architecture: x86_64 (amd64)
Type of failure: Runtime | Difficulty: Unknown
performance bug | Blocked By:
Test Case: | Related Tickets:
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by snoyberg):
Apologies if this is becoming repetitive, but here's a slightly simpler
version demonstrating the same issue:
{{{#!hs
import System.IO
data Sink i r = Sink (i -> Sink i r) r
sinkCount :: Sink i Int
sinkCount =
loop 0
where
loop cnt = Sink (\_ -> loop $! cnt + 1) cnt
feed :: Handle -> Sink Char r -> IO r
feed h =
loop
where
loop (Sink f g) = do
eof <- hIsEOF h
if eof
then return g
else do
c <- hGetChar h
loop $! f c
action :: IO ()
action = withBinaryFile "1mb" ReadMode $ \h -> do
feed h sinkCount
return ()
main :: IO ()
main = do
action
action
}}}
The following code, however, does *not* demonstrate the problem:
{{{#!hs
import System.IO
data Sink i r = Sink (i -> Sink i r) r
sinkCount :: Sink i Int
sinkCount =
loop 0
where
loop cnt = Sink (\_ -> loop $! cnt + 1) cnt
feed :: Sink Char r -> IO r
feed =
loop 10000000
where
loop 0 (Sink _ g) = return g
loop i (Sink f _) = loop (i - 1) (f 'A')
action :: IO ()
action = do
feed sinkCount
return ()
main :: IO ()
main = do
action
action
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9520#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list